Help with saving script

Talk about making games.

Help with saving script

Postby Sondise » Mon Jan 30, 2012 3:54 am

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);
User avatar
Sondise
 
Posts: 94
Joined: Thu Nov 01, 2007 11:04 pm
Location: South america
Score: 0 Give a positive score

Re: Help with saving script

Postby Leif » Mon Jan 30, 2012 5:25 am

All you need is stor data about your days in array. Than you can save/load it.
Repulsor beam + heavy cannons
User avatar
Leif
 
Posts: 147
Joined: Mon Dec 15, 2008 12:42 pm
Location: Moscow, Russia
Score: 10 Give a positive score

Re: Help with saving script

Postby Sondise » Mon Jan 30, 2012 7:25 pm

hm... Sorry but, how?
User avatar
Sondise
 
Posts: 94
Joined: Thu Nov 01, 2007 11:04 pm
Location: South america
Score: 0 Give a positive score

Re: Help with saving script

Postby skydereign » Wed Feb 01, 2012 1:15 am

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
}
User avatar
skydereign
 
Posts: 3452
Joined: Mon Jul 28, 2008 8:29 am
Score: 570 Give a positive score

Re: Help with saving script

Postby Sondise » Wed Feb 01, 2012 3:47 am

Oh, thanks a lot ^^
User avatar
Sondise
 
Posts: 94
Joined: Thu Nov 01, 2007 11:04 pm
Location: South america
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest