Your going to do an extra step to initialize that variable. So when your game loads, do something like
if (is_undefined(myvar))
{
myvar=true;
}
As an additional check for legacy save files. It obviously going to have to be appended to your loading procedure to catch if that variable was not created and create it.
How does you load file work, are you assigning them through a loop, or just assigning them with the assumption they are going to be there?
Unfortunately that method does not work because I checked that when the variable is not specified on the save file, GameMaker makes it 0, and that is not "undefined".
Some variables are assigned through a loop, yes. But that's not the case of this one. If you go a little bit up here you can see my code in one of my replies.
is_undefined can not and is not meant to be used to check if a variable exists.
Since you have full control over your save file, you should be capable of telling whether the save file provided is from an older version or not. One example of ensuring this is saving a version number inside the save file and incrementing it every time the save file format updates. This way, you will be able to add special cases to your save file loading code to ensure compatibility with all save file format versions - at least in the newest version of the game. Since you'll always know how each version of your save file format is structured (you documented that, right?), you'll always know how to treat a save file of the corresponding version.
That's as much detail as I can go into without seeing your code, but I don't think that will be necessary if you follow this approach, anyway.
I should have thought about that at the beginning!
But now it won't do to much, at least with this particular variable, since I did not save the game version previously.
I'll do it from now on, though.
If you want to check my code, go a little bit up this thread and you will find a reply with it, although I guess the proper way to solve this issue must be to create and individual file for this particular variable.
I was getting the impression it exists, it's not not getting set, unless I am totally misunderstanding him.
I think, just a guess, he is creating them on the front side, the loading them in to assign them. So his new version creates the variable, but the save file doesent have a value for it. But, like you said, without code it's a guess.
I posted the code in one of my replies, but for some reason it just disappeared.
So basically, the new variable I'm talking about is "
global.xmas".
Here is the end of the code for the script that runs at the very start of the game to
initialize all global variables:
Code:
//Control
global.cottoncandy = 0;
global.facebook = 0;
global.xmas = true;
//Load Game
load_game();
Here is the end of the code for "
Load Game":
Code:
//Control
global.cottoncandy = file_text_read_real(load);
file_text_readln(load);
global.facebook = file_text_read_real(load);
file_text_readln(load);
global.xmas = file_text_read_real(load);
file_text_readln(load);
//Close the file
file_text_close(load);
And here is the code for "
Save Game":
Code:
//Control
file_text_write_real(file, global.cottoncandy);
file_text_writeln(file);
file_text_write_real(file, global.facebook);
file_text_writeln(file);
file_text_write_real(file, global.xmas);
file_text_writeln(file);
//Close the file
file_text_close(file);
When I first run the update, the last saved variables are "
global.cottoncandy" and "
global.facebook". Of course "
global.xmas" does not exist there (though it is initialized at the first script as "true") so GameMaker sets it as 0.