Skip to main content
GameDev.net gamedev.net
🔒 Locked

[PyGame] Finding Variable Types

Started by GarrickW Mar 27, 2011 at 7:27 AM 1 replies 1.2k views
Original Post
GarrickW
GarrickW
So I'm trying to update my save-game function, and as I found out a month or so ago, Python's Pickler can't handle PyGame's Surface objects. So this is no problem, I have a valid workaround. Problem is, today I tried running the save method, and it tells me there are Surface objects lying around I haven't prepared for pickling. I don't get this; I've been careful when adding new Surface objects, I think, to make sure the saving code included preparing them. So I now have a main file with over 1200 lines of code, and about 8 modules in addition to the main file, that I need to comb through to find any and all Surface objects. Thing is, Surface object's aren't always marked as such in the code (in mine, they almost never are), so I need to find them some other way than a simple textual search (I tried that with the things that do mark Surface objects anyway, and it didn't give me any clues).

My first instinct was, rather than pickling the whole game, I would pickle individual instances one at a time, to see where the error pops up. This hasn't yielded much, however, as the pickling seems to think there are Surface objects everywhere. Part of this, I thought, might be because each instance of stuff like items, projectiles, etc. have variables referencing the game, which contains everything; but I neutralized these variables, and the error still pops up.

So I'm at a loss as to how to figure out where the Surface objects are. Does anyone know any tricks for locating certain kinds of objects in the code, besides being careful in the first place?
EndersGames
EndersGames
Still working on your rpg eh? How is it going?

Last month your rpg-prototype code inspired me to start working on one myself. I am programming it in JAVA for android. Lots of fun so far. Mine is going to be old school NES like.

I haven't programmed an RPG in a decade or so, so now I have to relearn all the techniques I once did in visual basic. But the tile drawing routine stuck with me for a long time. Been a good project. Can't wait to see some good stuff from it.

Hey, if you want to shoot over a zip file of your code to me, I will be happy to give it a go over to find those elusive surfaces. Well, good luck on your game.

-Brian
Esys
Esys
You can try[font="Lucida Console"] type(variable) == pygame.Surface [/font][font="Arial"]or [/font][font="Lucida Console"]isinstance(variable, pygame.Surface).[/font]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.