Page 1 of 1

Pygame

Posted: Tue May 15, 2012 3:52 am
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.

Re: Pygame

Posted: Tue May 15, 2012 5:01 am
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.

Re: Pygame

Posted: Tue May 15, 2012 1:49 pm
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.

Re: Pygame

Posted: Wed May 16, 2012 6:11 am
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.

Re: Pygame

Posted: Wed May 16, 2012 1:37 pm
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.....

Re: Pygame

Posted: Wed May 16, 2012 2:31 pm
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.

Re: Pygame

Posted: Wed May 16, 2012 2:46 pm
by Darktiger138
Which solution :|

Re: Pygame

Posted: Wed May 16, 2012 3:10 pm
by 3ICE
The
Darktiger138 wrote:1 part of the animation per run through
one.

Re: Pygame

Posted: Wed May 16, 2012 3:11 pm
by Darktiger138
Ah, ok, I'll implement that one.