Pygame
Forum rules
• If you are posting source code, proper indenting and comments will improve the readability.
• If you are posting source code, proper indenting and comments will improve the readability.
-
- Posts: 113
- Joined: Fri Apr 13, 2012 2:48 pm
- Realm: US East
- Account: Darktiger138
- Clan: THP
- Location: New Zealand
Pygame
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:
- 3ICE
- Admin
- Posts: 2631
- Joined: Sat Mar 01, 2008 11:34 pm
- Realm: Europe
- Account: 3ICE
- Clan: 3ICE
- Location: Hungary
- Contact:
Re: Pygame
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.
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.
-
- Posts: 113
- Joined: Fri Apr 13, 2012 2:48 pm
- Realm: US East
- Account: Darktiger138
- Clan: THP
- Location: New Zealand
Re: Pygame
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:
- 3ICE
- Admin
- Posts: 2631
- Joined: Sat Mar 01, 2008 11:34 pm
- Realm: Europe
- Account: 3ICE
- Clan: 3ICE
- Location: Hungary
- Contact:
Re: Pygame
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.
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.
-
- Posts: 113
- Joined: Fri Apr 13, 2012 2:48 pm
- Realm: US East
- Account: Darktiger138
- Clan: THP
- Location: New Zealand
Re: Pygame
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:
- 3ICE
- Admin
- Posts: 2631
- Joined: Sat Mar 01, 2008 11:34 pm
- Realm: Europe
- Account: 3ICE
- Clan: 3ICE
- Location: Hungary
- Contact:
Re: Pygame
Or use threading: google.com/search?q=pygame+threading+animations
But yes, the solution you proposed would work just as well if not better.
But yes, the solution you proposed would work just as well if not better.
-
- Posts: 113
- Joined: Fri Apr 13, 2012 2:48 pm
- Realm: US East
- Account: Darktiger138
- Clan: THP
- Location: New Zealand
-
- Posts: 113
- Joined: Fri Apr 13, 2012 2:48 pm
- Realm: US East
- Account: Darktiger138
- Clan: THP
- Location: New Zealand
Who is online
Users browsing this forum: No registered users and 9 guests