Save game?

Talk about making games.

Save game?

Postby ingsan » Wed Feb 18, 2004 11:18 am

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 ? :?
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Wed Feb 18, 2004 1:01 pm

No easy way, now.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby ingsan » Wed Feb 18, 2004 9:11 pm

but is it actually possible ? even if it's not easy to do so.
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Thu Feb 19, 2004 1:35 am

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby ingsan » Thu Feb 19, 2004 11:12 am

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:
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Thu Feb 19, 2004 1:33 pm

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby ingsan » Thu Feb 19, 2004 2:38 pm

CooL 8)
i'm gonna try that.

Thanx maxeslane :P
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby ingsan » Thu Feb 19, 2004 3:13 pm

what does "arq" stands for ?

does it have to do with error correction or something like that ?
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby ingsan » Thu Feb 19, 2004 6:46 pm

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:
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Fri Feb 20, 2004 2:18 pm

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"
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Mmm..

Postby ingsan » Fri Feb 20, 2004 5:46 pm

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:
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Sat Feb 21, 2004 6:17 pm

The var arq is a pointer to the your file.
Remove the "int lives = 0;" code.
What's happened?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby ingsan » Sat Feb 21, 2004 9:16 pm

it says

Line 7 : Undeclared Identifier Lives
Line 17 : Must have lvalue
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Postby makslane » Sun Feb 22, 2004 8:57 pm

Can you send me your .ged file?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby ingsan » Mon Feb 23, 2004 10:01 am

OK
User avatar
ingsan
 
Posts: 580
Joined: Mon Nov 17, 2003 4:02 pm
Location: Maurician LADY in FRANCE
Score: 6 Give a positive score

Next

Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron