Page 1 of 2

Save game?

PostPosted: Wed Feb 18, 2004 11:18 am
by ingsan
can we actually be able to "save" our game before quiting ?

For example, the score that we have made and all the levels that we have already accomplished...our variables also...

and resume our game later ? :?

PostPosted: Wed Feb 18, 2004 1:01 pm
by makslane
No easy way, now.

PostPosted: Wed Feb 18, 2004 9:11 pm
by ingsan
but is it actually possible ? even if it's not easy to do so.

PostPosted: Thu Feb 19, 2004 1:35 am
by makslane
You can save and load vars by using fopen, fprintf, fscanf, fclose C functions.

But is not a very thing...
In the next version Game Editor will do save and load vars

PostPosted: Thu Feb 19, 2004 11:12 am
by ingsan
Cool... 8)

So, what i have understood is that, with these C functions, i can actually save the vars that i created. :?

then, to be able to save my .exe and close it without being afraid of losing what i did, i have to create vars that will actually save all data of my game. i'm sorry to annoy u but how can i do so, since i'm new to programming :?

THanx anyway, maxeslane... :wink:

PostPosted: Thu Feb 19, 2004 1:33 pm
by makslane
Quick and dirty:

To save and load a var lives, go to the Global Code editor and
put this code:

Code: Select all
int lives = 0;

void saveLives()
{
   FILE *arq = fopen("lives", "wb");
   if(arq)
   {
      fprintf(arq, "%ld", lives);
      fclose(arq);
   }
}

void loadLives()
{
   FILE *arq = fopen("lives", "rb");
   if(arq)
   {
      fscanf(arq, "%ld", &lives);
      fclose(arq);
   }
}



Now, you can use loadLives and saveLives in your game

PostPosted: Thu Feb 19, 2004 2:38 pm
by ingsan
CooL 8)
i'm gonna try that.

Thanx maxeslane :P

PostPosted: Thu Feb 19, 2004 3:13 pm
by ingsan
what does "arq" stands for ?

does it have to do with error correction or something like that ?

PostPosted: Thu Feb 19, 2004 6:46 pm
by ingsan
i have a MainActor and a score named "lives" :

on "lives" :
add Event CreateActor
add Action Script Editor and write :


count=0;

// count being a global variable.


on MainActor :
add Event KeyDown ( c-key )
add Action Script Editor and write :

count++;
lives.TextNumber=count;


So, when i press "c", my score increases.

Then what i did is the following :

Create New Actor named "test".

add Event Draw Actor
add Action Script Editor and write :


int count=0;

void saveFiles()
{
FILE *arq = fopen ("count" , "wb");

if (arq)
{
fprintf (arq, "%dl", count);
fclose (arq);
}
}

void loadFiles()
{
FILE *arq = fopen ("count" , "rb");

if(arq)
{
fscanf (arq, "%dl", &count);
fclose (arq);
}
}


Still when i press on Add, it says = Redeclaration of "count".
Have i misunderstood something ? :oops:

PostPosted: Fri Feb 20, 2004 2:18 pm
by makslane
Errors:

1) you must put the save and load code on "Global Code" editor
2) "%dl" -> "%ld"
3) you can't create count on "New Variable" panel and "Global Code"

Mmm..

PostPosted: Fri Feb 20, 2004 5:46 pm
by ingsan
So "count" is really a variable.

and what for what u wrote i.e "arq" ? >>See previous message. :?

i also replace "count" by "lives" but still Error on line 1 :

Code: Select all
 int lives=0;


where it says that i have to "redeclare" parameter " lives" :cry:

PostPosted: Sat Feb 21, 2004 6:17 pm
by makslane
The var arq is a pointer to the your file.
Remove the "int lives = 0;" code.
What's happened?

PostPosted: Sat Feb 21, 2004 9:16 pm
by ingsan
it says

Line 7 : Undeclared Identifier Lives
Line 17 : Must have lvalue

PostPosted: Sun Feb 22, 2004 8:57 pm
by makslane
Can you send me your .ged file?

PostPosted: Mon Feb 23, 2004 10:01 am
by ingsan
OK