|
metadata
Ok. Im trying to make a save file in the game but the only idea I have is to make a function that preserves the variables after the NewGame function by duplicating them. The problem is that if it works, it would only preserves the variables if the player didnt leave the game. Does any one knows how to acess the save files codes?
|
|
|
metadata
Go to google and search Flash SharedObjects.
|
|
|
metadata
Ill try that. Thanks man.
|
|
|
metadata
this is advanced Flash code! i dont understand it!
|
|
|
metadata
No it’s not.
`
onClipEvent(load) {
//lets open our "save file"
_global.SavedGame=SharedObject.getLocal("file_name");
//I used "file_name" as my saved file's name, call it whatever you want.
//I made my save file a global variable so I can access it from anywhere, even though I only access it from this script. Good practice? Maybe not, depends on how you want to access your stuff!
//wait, what if it doesn't exist?
if(_global.SavedGame.data.SAVED_VARIABLE==null) {
//ok, if it doesn't exist, create it!
//I've saved a line here, and some typing by assigning my global variable that checks to see if the award has been award yet and the save file data to the same thing: false.
_global.SavedGame.data.SAVED_VARIABLE = _global.SAVED_VARIABLE = false;
//do this for all your saved variables
//now save that data out!
_global.SavedGame.flush()
}
//ok, but what if it does exist?
else {
//load!
_global.SAVED_VARIABLE = _global.SavedGame.data.SAVED_VARIABLE;
//and do it for every other variable
}
}
`
That’s _everything_ you need to know. I showed you the creation of the .sol file, loading data from it, sending data to it, saving data, as well as initializing your file for the first time (this is where data was sent).
If you want to delete the data, because maybe you want an in-game way to delete it in order to save your users the time finding the file themselves, use \_global.SavedGame.clear();
BTW, “SavedGame” is a variable name, just like any other variable, you can have “SavedGame1” and “SavedGame2” if you want!
|
|
|
metadata
So thats a hole script function of loading and saving? Thanks! Ill post in my game.
|
|
|
metadata
but that would make a save only when it tryed to load. To make a save game button i hav to get these lines
`
global.SavedGame.data.SAVEDVARIABLE = global.SAVEDVARIABLE = false;
global.SavedGame.flush()
`
And a load should be like this:
`
global.SavedGame=SharedObject.getLocal("filename");
global.SAVEDVARIABLE = global.SavedGame.data.SAVEDVARIABLE;
`.
I guess its better this way cuz I dont see any games with a load/save button. This script creates a save when I send “load” if a save file is null, but what if I only wanna create a save file?
|
|
|
metadata
I gave you all the code, its up to you to figure out how you want to use it.
I use another chunk of code that every time a game finishes it saves any new awards received.
But yes, your two code snippets are correct.
To create a save file without loading just do the getLocal function followed by a flush. That’ll give you an empty file. If you put some global.SavedGame.data.SAVEDVARIABLE = global.SAVEDVARIABLE; stuff in between you’ll create a save with data in it.
|
|
|
metadata
|
|
|
metadata
|
|
|
metadata
Another thing, your first line
`onClipEvent(load) { `
Is it right or we need to make a function?
|
|
|
metadata
Oh, I stuck all of that on a movieclip (my award menu).
|
|
|
metadata
so if I put it to a normal function wont be difference?
|
|
|
metadata
Nope. You just have to remember to call it from somewhere.
|
|
|
metadata
|
|
|
metadata
I have one more question when it comes to the save and load system how do I make an overwriting code?
|
|
|
metadata
.Sol, huh? Haven’t used it for a while.
|
|
|
metadata
> *Originally posted by **[Jotamota](/forums/11/topics/30864?page=1#posts-617885):***
>
> thanks I’ll try that.
Once you find one don’t try the others
|