Pygame

Community for Programmers and Developers. C, C++, C#, Basic, Perl, VB, VBS, Java, Javascript, PHP, CGI, HTML and More!
• If you are posting source code, proper indenting and comments will improve the readability.

Pygame

New postby Darktiger138 on 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.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5
Darktiger138
 
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Location: New Zealand
Realm: US East
Account: Darktiger138
Clan: THP

Re: Pygame

New postby 3ICE on Tue May 15, 2012 5:01 am

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
User avatar
3ICE
Admin
 
Posts: 2100
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Pygame

New postby Darktiger138 on 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.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5
Darktiger138
 
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Location: New Zealand
Realm: US East
Account: Darktiger138
Clan: THP

Re: Pygame

New postby 3ICE on 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.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2100
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Pygame

New postby Darktiger138 on 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.....
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5
Darktiger138
 
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Location: New Zealand
Realm: US East
Account: Darktiger138
Clan: THP

Re: Pygame

New postby 3ICE on 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.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2100
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Pygame

New postby Darktiger138 on Wed May 16, 2012 2:46 pm

Which solution :|
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5
Darktiger138
 
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Location: New Zealand
Realm: US East
Account: Darktiger138
Clan: THP

Re: Pygame

New postby 3ICE on Wed May 16, 2012 3:10 pm

The
Darktiger1381 part of the animation per run through
one.
ImageImageImageImageImage
Image
ImageImage
User avatar
3ICE
Admin
 
Posts: 2100
Joined: Sat Mar 01, 2008 11:34 pm
Location: Hungary
Realm: US East
Account: 3ICE
Clan: 3ICE

Re: Pygame

New postby Darktiger138 on Wed May 16, 2012 3:11 pm

Ah, ok, I'll implement that one.
Spoiler:
Spoiler 1
Spoiler:
Spoiler 2
Spoiler:
Spoiler 3
Spoiler:
Spoiler 4
Spoiler:
Spoiler 5
Darktiger138
 
Posts: 113
Joined: Fri Apr 13, 2012 2:48 pm
Location: New Zealand
Realm: US East
Account: Darktiger138
Clan: THP


Return to Programming



Who is online

Users browsing this forum: No registered users and 1 guest

cron