🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

PyGame blitting and game loop error

Started by
5 comments, last by DakeDesu 20 years, 11 months ago
Hullo, I am trying to learn Python for the purpose of client end GUI development. I am using ActivePython 2.2 Build 224, and am currently unable to use the debugger in IDLE (as apparently break points do not work >:/ ). I am currently working a Stick Fighter script, using pygame, and it is not blitting to the surface, or doing the game loop. I am wondering what resources are available for documentation (the docs that came with wxPython suck, and Tkinter docs seem to be nonexistant, however pygame''s are not too bad), as well as decent IDEs for Python (IDLE does not like me, and Komodo crashes too much). Any pointers to a programmer new at Python RAD? "You''re right, Bush has no place in a thread about masturbation." -- griffenjam Got Immortality? [edited by - Timestamp_Zero on January 1, 1970 00:00:00 AM]
[ Six Hour Game Contest | ( Thread | Blog | Wiki | 6hour Bio ) ][ Website | (Blog | Gallery ) ]
Advertisement
First, change red to ''red'' and blue to ''blue''

Second, your __setattr__ is redundant. It''s currently (after fixing the red/blue error) going in an infinite loop. You see, it''s calling itself to set self.name to value. Python objects are inherently mutable, so adding that is not necessary to make it so, if that''s what you''re trying to do. __setattr__ is for when you want to change something''s internal implementation, and you want to have things like length still be a simple variable instead of a function. In which case, you''d still need to raise an AttributeError so that Python knows to use the default action (direct manipulation) instead of your custom action.

Third, the most common thing to do to check the type of your argument is to use isinstance(instance, class). It should work anyway.

Fourth, your position_paul apparently needs an argument. Assuming stickman

Fifth, when exactly do you think it should be drawing this? Apparently draw_man is never called. Fixed it by adding:
    for figure in paul, john:        figure.draw_man(screen)    pygame.display.flip() 


Sixth, even if draw_man *was* called, it would expect a screen object as its parent. I don''t think that''s what you meant. Member objects take self as their first argument, always.

Seventh, there''s a typo on line 22. I don''t know what it''s supposed to say, but self_top_pos is not recognized.

Eighth, circle_pos needs to be a tuple. Currently, you have it as some sort of bastard hybrid of an integer and a tuple. You can''t add an integer and a tuple. Fix it by using this:
circle_pos = self.body_top_pos[0], self.headsize + self.body_top_pos[1] 

There''s probably an easier way to do it, but I don''t know what it is.

Congratulations. You now have a program that draws two stick-figures upside-down. (vertical values are numbered counting down)

As far as an IDE goes, I''ve never needed one. Typically, what I do for debugging is use a prompt, add my project directory to my sys.path, and import my module. Then I use the interactive prompt to poke the problematic code. (run each function one at a time and see which one is breaking it and the nature of the break) I haven''t needed anything fancier.

For just entering code into a file, I use SciTE (a simple wrapper around Scintilla)
---New infokeeps brain running;must gas up!
ConText is a notepad replacement that supports syntax highlighting and other stuff for multiple languages. It isn''t a full fledged IDE, but it works nicely for Python.

If you want a full fledged IDE, try Eclipse with the TruStudio Python plugin. (eclipse.org, trustudio.com) I like it much better than IDLE.

Python 2.3 was just released (python.org), it comes with a new version of IDLE, maybe your breakpoint problem is fixed in this version.

Tkinter docs: I searched Google for ''tkinter docs'' and got several results. Here''s one I used to learn tkinter: http://www.pythonware.com/library/tkinter/introduction/index.htm
Edit:
quote: Third, the most common thing to do to check the type of your argument is to use isinstance(instance, class). It should work anyway.


It tells me that isinstance() has not been defined... what do I have to import to get it?

quote: Original post by Flarelocke
First, change red to 'red' and blue to 'blue'


Whoops.

quote: Second, your __setattr__ is redundant. It's currently (after fixing the red/blue error) going in an infinite loop. You see, it's calling itself to set self.name to value. Python objects are inherently mutable, so adding that is not necessary to make it so, if that's what you're trying to do. __setattr__ is for when you want to change something's internal implementation, and you want to have things like length still be a simple variable instead of a function. In which case, you'd still need to raise an AttributeError so that Python knows to use the default action (direct manipulation) instead of your custom action.


Thanks, I did not know that __setattr__ wasn't an abstract function (or whatever undefined virtual functions are called.).

quote: [bunch of corrections to silly mistakes I did]


Whoops... sorry that you had to do my debugging for me.

quote: Congratulations. You now have a program that draws two stick-figures upside-down. (vertical values are numbered counting down)


Okay, thanks, now I know pygame does not work the same as Postscript

quote: As far as an IDE goes, I've never needed one. Typically, what I do for debugging is use a prompt, add my project directory to my sys.path, and import my module. Then I use the interactive prompt to poke the problematic code. (run each function one at a time and see which one is breaking it and the nature of the break) I haven't needed anything fancier.

For just entering code into a file, I use SciTE (a simple wrapper around Scintilla)


Thanks, I am currently running a windows box with this (of course you knew that when I said ActivePython), and was unaware that Scintilla was available for windows. Thanks!

[edited by - DakeDesu on August 1, 2003 5:12:46 PM]
[ Six Hour Game Contest | ( Thread | Blog | Wiki | 6hour Bio ) ][ Website | (Blog | Gallery ) ]
isinstance is a builtin -- you don''t need anything to import it. Why are you using ActivePython? Why not just use the regular python? As the other poster mentioned, Python 2.3 is out, and there''s a brand new IDLE inside (IDLEFORK has been merged back)

quote: Thanks, I did not know that __setattr__ wasn''t an abstract function (or whatever undefined virtual functions are called.).
Well, Python objects aren''t by default a subclass of some Object class, like they are in some other languages, so it isn''t exactly accurate to say that __setattr__ is an abstract function. The python language demands a certain behavior (mutable arguments), and __setattr__ can modify that behavior.

---New infokeeps brain running;must gas up!
quote: Original post by Flarelocke
isinstance is a builtin -- you don''t need anything to import it. Why are you using ActivePython? Why not just use the regular python? As the other poster mentioned, Python 2.3 is out, and there''s a brand new IDLE inside (IDLEFORK has been merged back)


Well, I just assumed that since ActiveState had a binary of it, it would be the latest version of a prebuilt binary on windows systems. Perl.org just links to ActiveState for its windows binary, and ActiveState, just points to php.net for the latest binary. So in conclusion it was just a little confusion (I am downloading the latest version of 2.3 from python.org).

quote:
quote: Thanks, I did not know that __setattr__ wasn''t an abstract function (or whatever undefined virtual functions are called.).
Well, Python objects aren''t by default a subclass of some Object class, like they are in some other languages, so it isn''t exactly accurate to say that __setattr__ is an abstract function. The python language demands a certain behavior (mutable arguments), and __setattr__ can modify that behavior.


So, it is similar to objects defined in perl''s UNIVERSAL namespace.
[ Six Hour Game Contest | ( Thread | Blog | Wiki | 6hour Bio ) ][ Website | (Blog | Gallery ) ]
> Well, I just assumed that since ActiveState had a
> binary of it, it would be the latest version of a
> prebuilt binary on windows systems.

It usually is, but python 2.3 was released a week ago.

This topic is closed to new replies.

Advertisement