Page 1 of 1

Loading saved games (woes and more woes)

PostPosted: Thu Feb 16, 2006 2:14 am
by plinydogg
I feel like I've learned a lot about using Game Editor in the past few months (mainly thanks to you guys) and my first game is all but complete...but for the life of me I have not been able to successfully add even A SINGLE ONE of the handful of features I wanted to add...frustrating!!!

The latest issue is that I can't properly load saved games. There are only three variables I need to save: level, score, and lives. Simple right? I know how to use saveVars/loadVars (I use them to store and retrieve the highscore), but everything is messed up when I try to use them to restore these three variables (savedLevel, savedScore, and savedLives).

Here's what I did:

(1) Created a global int gameInProgress (part of the "save" group). Its value is 0 by default. When the MainShip is created, gameInProgress is set equal to 1. When the player loses all lives (i.e., when the game is over) it is set back to 0. If the player presses the exit button before the game is over, the three variables (level, score, and lives) are saved as savedLevel, savedScore, and savedLives (in the "save" group). gameInProgress (now equal to 1) is also saved.

(2) When the player restarts the game, the "save" group is loaded and if gameInProgress == 0, the game starts as it normally would. If, however, gameInProgress == 1, then the title screen is avoided and the game starts as it normally would, except that level, score, and lives are set equal to savedLevel, savedScore, and savedLives. Simple enough right?

The problem is that a whole bunch of stuff goes wrong: actors lose their parent-child relationships (even though I included these commands in script; the fire button always shoots in one direction (to the side of the screen, etc.).

These problems are reminiscent of problems I've had in the past that occurred when events were sent to actors that were outside of the activation region, but I can't understand why. Why should the activation region matter for variable assignment?

Can anyone figure anything out?

Thanks in advance,

[A whimpering] Plinydogg

PostPosted: Thu Feb 16, 2006 2:54 pm
by makslane
What's your Game Editor version?

PostPosted: Thu Feb 16, 2006 3:40 pm
by plinydogg
1.3.3

PostPosted: Thu Feb 16, 2006 11:30 pm
by plinydogg
Okay, I found a workaround although I'm not sure why it works and the other way didn't.

***The old way:***

The variables level, score, and lives were created and initialized when the game started via the global code editor (e.g., int lives = 3;. When the game started, I put the following script on the splash screen->create actor->script editor:

loadVars("game.sav", "save"); //loads the group with the saved variables
if(gameInProgress == 1)
{
lives = savedLives;
score = savedScore;
level = savedLevel;
}
else
{
lives = 3; //if there's no game in progress, assign default values
score = 0;
level = 1;
}

For whatever reason, this didn't work.

***The new way:***

I created the variables level, score, and lives in the same place but I did not initialize them (i.e., instead of int level = 1; I wrote int level;. Then I created a function (in the global code editor):

void testForSave()
{
loadVars("game.sav", "save");
if(gameInProgress == 1)
{
lives = savedLives;
score = savedScore;
level = savedLevel;
}
else
{
lives = 3;
score = 0;
level = 1;
}
}

I then called this function in the same place as the old code: splash screen->create actor-> script editor.

This works perfectly! But why?

PostPosted: Fri Feb 17, 2006 1:06 am
by makslane
I think is a bug.
Can you send me a little game with both save ways?