Page 1 of 1

Saving clones XY postions

PostPosted: Thu Apr 09, 2009 12:45 am
by Rux
I'm making a game where, you have to press a button to place something. But I want to be able to save the X Y positions of all the placed objects, a specified number in a text box, a velocity in a text box, the name in a textbox, and an audio file path in a textbox. I want to save all those. How can I save variables and text into one file? Also how do you load the data, place the cloned notes in the same postions, play the audio (OGG) file path, set the specified number to a string, and move an object up in the saved velocity? I know it seems like a lot but I really need help to all those who are good at saving things. :(

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 1:17 am
by skydereign
Well, you could save each of these into individual files, if they are separate. Or save all into one. Here is an example, I can get more specific if need be. It only shows how to save the xy of actors, limited if you don't know how to make a dynamic array, and save char*s.
Code: Select all
void
varLoad (void)
{
  int actorNum;
  FILE * VARS = fopen("gameVars", "r");
  fscanf(VARS, "%d,/n", &actorNum);
  for(i=0; i<actorNum, i++)
  {
     fscanf(VARS, %d, %d,/n", &actorX[i], &actorY[i]); // actorX/actorY would be int arrays in global code
  }
  fscanf(VARS, "%s,/n", &TEXT); // TEXT is a char*, you could also just use the text actor's text variable
  // you would repeat the above for any strings you want
  // if any of the ones I did not explain you don't know how to do, just ask
  fclose(VARS);
}

void
varSave(void)
{
  int actorNum = sizeof(actorNum)/sizeof(int);
  FILE *map = fopen("gameVars", "w");
  fprintf(VARS, %d,/n", actorNum);
  for (i=0; i<actorNum; i++)
  {
     fprintf(VARS, %d, %d,/n", actorX[i], actorY[i]);
  }
  fprintf(VARS, "%s,/n", TEXT);
  fclose(VARS);
}

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 1:23 am
by Rux
um, is this the ONLY way to do it? could my task be done with the simple saveVar, loadVar functions? Just wondering.

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 1:31 am
by stevenp
no theres another way 1 sec, we used the same method in music box last year let me find it

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 2:27 am
by stevenp
see DST's post a few posts down

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 3:24 am
by skydereign
But if it is simply done with save/loadVar, then isn't it simply done? I was under the impression that with save/load vars, it was just calling the function to save a group, then load it. So it is just variable manipulation, actor count, velocity, all the things you listed. Which in some cases is easier, but the method is the same... One is applied using separate calls, the other all at once. I guess if you don't know scripting it seems a lot harder, but the idea is the same, and using your own function makes it easier to manipulate... Then again, I don't really use the save/load vars so I don't really know.

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 3:45 am
by Rux
My main problem was how to save CLONES that were created in the game, not in GE.

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 6:32 am
by DST

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 10:54 am
by equinox
----

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 11:37 am
by stevenp
DST wrote:http://game-editor.com/forum/viewtopic.php?f=5&t=5703&hilit=+save+user+clones


thanks, i was trying to find that post, but makslane took out the " search for post" method on the website

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 12:13 pm
by equinox
Hi at ALL,

I change the code, but not charged CHAR the data. What s wrong?

tNK1000 FOR HELP.

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 12:15 pm
by skydereign
-Equinox
Change it to this, if you are using a set array some of the code is pointless, and maybe non-functioning.
-Edit, this was for your previous post
Code: Select all
int VAR[13];
char *TEXT;

void varSave(void){
  int i = 0;
   FILE *VARS = fopen("gameVars", "w");
  for (i=0; i < 13; i++)
  {
    fprintf(VARS, "%d", VAR[i]);
  }
  //  fprintf(VARS, "%s", TEXT);
  fclose(VARS);
}
void varLoad (void){
  int i = 0;
  FILE * VARS = fopen("gameVars", "r");
  for(i=0; i < 13; i++){
    fscanf(VARS, "%d", &VAR[i]);
  }
  //  fscanf(VARS, "%s", &TEXT);
  fclose(VARS);
}

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 1:04 pm
by equinox
Tnk Sky for help.

But i wish the print in this way and I can not print the CHAR:(and not all data on the same line image1)

FILE.rar
GLOBAL CODE
int VAR[4][4]; A B C
char *ICON[3][3];// OR char ICON[3][3][3]--> A = 3 ACTOR x 3 ITEM x ITEM_NAME.LEN = 3


FILE*file;// **** SAVE *******
VAR[0][0] = 111;
VAR[0][1] = 222;
VAR[0][2] = 333;

ICON[0][0] = "A";
ICON[0][1] = "B";
ICON[0][2] = "C";

file = fopen("TextNote.txt", "w");
fwrite(&VAR, sizeof(VAR), 1, file);
fwrite(&ICON, sizeof(ICON), 1, file);
fclose(file);
//********************
FILE*file;//*** LOAD INT
file = fopen("TextNote.txt", "r+");
fread(&VAR, sizeof(VAR), 1, file);
fclose(file);

A1.textNumber = VAR[0][0];
A2.textNumber = VAR[0][1];<<<<<-----WORK
A3.textNumber = VAR[0][2];
//***********************
FILE*file;//*** LOAD CHAR E PRINT
file = fopen("TextNote.txt", "r+");
fread(&ICON, sizeof(ICON), 1, file);
fclose(file);

//strcpy(A1.text, ICON[0][0]);
sprintf(getclone2(A1.name, 0)->text ,"ICON:%d",ICON[0][0]);<<<<<<<<----NOT WORK


Can yuo help me,please?

Re: Saving clones XY postions

PostPosted: Thu Apr 09, 2009 6:34 pm
by Rux
DST wrote:http://game-editor.com/forum/viewtopic.php?f=5&t=5703&hilit=+save+user+clones

Thanks a lot! This may take me a while, because there are 15 different things that need to be saved.
:D