Page 1 of 1
Posted: Tue May 15, 2012 3:52 am
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.
Posted: Tue May 15, 2012 5:01 am
Sure is! The feature is called threading:
Search queries I'd try:
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.
Posted: Tue May 15, 2012 1:49 pm
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.
Posted: Wed May 16, 2012 6:11 am
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.
Posted: Wed May 16, 2012 1:37 pm
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.....
Posted: Wed May 16, 2012 2:31 pm
Or use threading: google.com/search?q=pygame+threading+animations
But yes, the solution you proposed would work just as well if not better.
Posted: Wed May 16, 2012 2:46 pm
Posted: Wed May 16, 2012 3:10 pm
Darktiger138 wrote:1 part of the animation per run through
Posted: Wed May 16, 2012 3:11 pm
Ah, ok, I'll implement that one.