Pygame

Community for Programmers and Developers. C, C++, C#, Basic, Perl, VB, VBS, Java, Javascript, PHP, CGI, HTML and More!
Forum rules
• If you are posting source code, proper indenting and comments will improve the readability.
Darktiger138
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Realm: US East
Account: Darktiger138
Clan: THP
Location: New Zealand

Pygame

Unread post by Darktiger138 »

So I'm working on a crappy little game using the Python module Pygame, just for the hell of it, and I was wondering if it is possible to run two scripts, or two lines of the same script, at the same time. Or just run one line of script constantly while the rest of the script runs without interruption, or interrupting, that line of script.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5

User avatar
3ICE
Admin
Posts: 2509
Joined: Sat Mar 01, 2008 11:34 pm
Realm: Europe
Account: 3ICE
Clan: 3ICE
Location: Hungary
Contact:

Re: Pygame

Unread post by 3ICE »

Sure is! The feature is called threading:
Search queries I'd try:
threaded python
python threading
threading in python

Edit: Pay more attention to topic titles please. "How to execute two functions at the same time in python" would have been so much nicer to look at.
ImageImageImageImageImage
Image
ImageImage

Darktiger138
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Realm: US East
Account: Darktiger138
Clan: THP
Location: New Zealand

Re: Pygame

Unread post by Darktiger138 »

That still uses the top down approach, and it just looks exactly like functions except using classes and adding the word thread into it and making a whole lot more complicated than it really is, or the tutorials I just read are crap.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5

User avatar
3ICE
Admin
Posts: 2509
Joined: Sat Mar 01, 2008 11:34 pm
Realm: Europe
Account: 3ICE
Clan: 3ICE
Location: Hungary
Contact:

Re: Pygame

Unread post by 3ICE »

Sorry, but programming is inherently linear. If you want threading (two functions executing alongside each other), you have to enter a whole new level of complicated python.

Of course your problem can most likely be solved in a linear fashion, you just have to rethink it. Your current solution is probably a bad approach.
ImageImageImageImageImage
Image
ImageImage

Darktiger138
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Realm: US East
Account: Darktiger138
Clan: THP
Location: New Zealand

Re: Pygame

Unread post by Darktiger138 »

Jeez, you just assume my solutions crap. It just that when a lengthyish part of my program has to run, such as a movement animation, the rest of the program pauses momentarily, I'll just have to add in another variable that slowly increments and does 1 part of the animation per run through. Or just add in parts of the rest of the code into where the animation is happening.....
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5

User avatar
3ICE
Admin
Posts: 2509
Joined: Sat Mar 01, 2008 11:34 pm
Realm: Europe
Account: 3ICE
Clan: 3ICE
Location: Hungary
Contact:

Re: Pygame

Unread post by 3ICE »

Or use threading: google.com/search?q=pygame+threading+animations

But yes, the solution you proposed would work just as well if not better.
ImageImageImageImageImage
Image
ImageImage

Darktiger138
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Realm: US East
Account: Darktiger138
Clan: THP
Location: New Zealand

Re: Pygame

Unread post by Darktiger138 »

Which solution :|
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5

User avatar
3ICE
Admin
Posts: 2509
Joined: Sat Mar 01, 2008 11:34 pm
Realm: Europe
Account: 3ICE
Clan: 3ICE
Location: Hungary
Contact:

Re: Pygame

Unread post by 3ICE »

The
Darktiger138 wrote:1 part of the animation per run through
one.
ImageImageImageImageImage
Image
ImageImage

Darktiger138
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Realm: US East
Account: Darktiger138
Clan: THP
Location: New Zealand

Re: Pygame

Unread post by Darktiger138 »

Ah, ok, I'll implement that one.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests