Page 1 of 1

Help with saving script

PostPosted: Mon Jan 30, 2012 3:54 am
by Sondise
Hello guys, I haven't been using game editor for a long while, so I forgot about many things I knew, but anyways. I'm doing something like a calendar, but I'm having many problems in saving it. It's a very simple "game", I have the days (cloned actors, but with different animations for each day). When I click, a cross appears over the date. (I used: Mouse button down (in the day actor) » Script Editor (1)). On the cross, I use Mouse Button Down » Destroy Actor, so I can "uncross" the day if I want to. That's all I've done. But now I want to save it. I mean, when I close the game, and open it agian, everything that I crossed, remais crossed. That's what I want to do, but I can't. Could you please help me? Thanks

Script (1):
CreateActor("cross", "Tap", "(none)", "(none)", 0, 0, false);
ChangeTransparency("cross", 0.297000);

Re: Help with saving script

PostPosted: Mon Jan 30, 2012 5:25 am
by Leif
All you need is stor data about your days in array. Than you can save/load it.

Re: Help with saving script

PostPosted: Mon Jan 30, 2012 7:25 pm
by Sondise
hm... Sorry but, how?

Re: Help with saving script

PostPosted: Wed Feb 01, 2012 1:15 am
by skydereign
Well I believe Lief is suggesting using gE's built in saving system. In that case you need to declare an array. To do so go into the script editor click [Variables] and [Add]. Type in the name of your variable, in this case I'd suggest something along the lines of month_array. It's by default set to be an int, now set it to be an array (change the [No] to a [Yes] and give it a size). In this case you'll want the size of the array to be 31 (assuming there is only one month). Last thing you need to do to create the array is to add it into a save group. So type in calender.

Now, in the cross' create actor you can add this code.
cross -> Create Actor -> Script Editor
Code: Select all
month_array[creator.cloneindex]=1; // this means an x is on that day

And when you destroy the cross you can add this.
cross -> Destroy Actor -> Script Editor
Code: Select all
month_array[creator.cloneindex]=0; // no x on the day


The idea behind this is that each day is represented by a sub in the month_array variable (it holds 31 possible days). When you click on a day, it sets the corresponding sub to 1, signifying that a cross has been put on that day. Destroying the cross removes it (sets the value back to 0).

Now that we have a way of tracking which days have been clicked, we can go to save it. I assume you want to save when you exit, so wherever you do choose to exit the game, you can add this.
Code: Select all
saveVars("calender", "calender"); // saves the variables in the calender save group into a file called calender

And when you load your game you want it to load the variables, so in the view's create actor, you can use the reverse operation loadVars.
view -> Create Actor -> Script Editor
Code: Select all
loadVars("calender", "calender");


And finally the actual recreating of the crosses. Since we were using cloneindex to determine which days had the cross, might as well use it again. In the actual days (the ones you click to create the crosses) add something like this to their create actor event.
day_display -> Create Actor -> Script Editor
Code: Select all
if(month_array[cloneindex]==1) // if this day had a cross on it
{
    //put your CreateActor function call here to create the cross on the day
}

Re: Help with saving script

PostPosted: Wed Feb 01, 2012 3:47 am
by Sondise
Oh, thanks a lot ^^