Nerdsworth Academy


A texture and shadow map of a temperate location.

Save / Load and GUI Bugs

Posted at
.

I hope that everyone out there on the Internet had a wonderful Thanksgiving!

I was out of the state and unfortunately didn’t have much time to work on Splatterfield. I did manage to spend some time watching the Colin Firth / Jennifer Ehle version of Pride and Prejudice, which is a nice change of pace from the HuskyStarcraft videos I usually watch.

When last we met

When I last left Splatterfield before the break, I had just figured out how to display buttons on the screen. I had also used pickle to dump out the battlefield to an external file.

So, naturally, I decided that the next step would be to hook up the “Save” and “Load” buttons to the save and load functionality.

Who would have thought that so much trouble would come from such a simple endeavor?

A most vexing bug

A simple DirectEntry object allows the users to input the name of the map that they are working on and save it to disk.

A simple DirectEntry object allows the users to input the name of the map that they are working on and save it to disk.

The workflow was going to be thus: clicking on either the “Save” or “Load” button would call a function to put a text input dialog screen where the player could enter in the name of the current map (for saving) or the name of the map that they wished to load.

Then, with a bit of wand-swishing, the game map would change to the appropriate map.

However, I got stuck for some four hours, with the dialog for saving opening upon the launch of the game. Yikes.

I could not track down the problem. I got an example from the Panda3D library and tried to get it to work in the manner that I wanted, but I kept getting stuck at one point or another.

I thought about trying some hacky stuff like hiding it temporarily or moving it off the screen, but ruled against it because I needed the GUI elements to function in a predictable manner (not to mention that this would be quite bad form).

No matter what I did, the dialog would open as soon as the game launched.

Agreeable Progress

With the saving and loading working properly, I can now make complex structures and save them for future use. Awesome!

With the saving and loading working properly, I can now make complex structures and save them for future use. Awesome!

Eventually I discovered that it had to do with the “command” parameter for the “Save” button. When building the “Save” button, you have the option of specifying a function that is called when the button is pressed.

However, I accidentally included the trailing parentheses for the function, which caused the function to run at the time that the button was created, not when the button was pressed.

So, I removed the parentheses and it just worked. I yelled a victory cry, and simultaneously cursed and praised the coding gods.

The code is still fairly buggy and doesn’t do any error checking just yet. So if, you know, you try to load a map that doesn’t exist or input invalid filename characters, the whole game explodes.

But it’s a step in the right direction and that’s how I like to work. One small task at a time.

I think my next step will be to add in the weaponry that I mentioned in my previous post. Either that or perhaps making it so that you can move soldiers around the map in a reasonable fashion.

Then, I might just be one step closer to having a cool game.


Comments

    Sunhawk said: 24 April 2013 at 22:14

    Yep. The only thing right now that it won’t save are any projectiles that are currently in the air (which actually cause the whole program to crash!).

Leave a Reply

Your email address will not be published.