Uh.. really advanced question o-o saving multi-animpos?

You must understand the Game Editor concepts, before post here.

Uh.. really advanced question o-o saving multi-animpos?

Postby Hblade » Thu Jan 03, 2013 3:43 am

[What I have now causes a hang in game-editor eventhough the process isn't loading o.O]

Maybe it's simple but... While writing the save script for the level, I came across something that disturbs me. I have a max of 250,000 tiles (500x500). the problem: I want to be able to save every animpos of each tile o.O My variables:
Code: Select all
#define TILES_X 500
#define TILES_Y 500

///////////////////////////////////////////////////////////////////////////////

  int
  mapSizeX,              mapSizeY,
  tileWidth,             tileHeight,
  GRIDSIZE,              tilePos[TILES_X][TILES_Y],
  layerCreated[4],       tileAnimpos[250000];
 
    //Allows up to 250000 tiles (500*500) to be placed for large, advanced maps.
 
//////////////////////////////////////////////////////////////////////////////


I need to know how each layer of tiles can have saved animpos o-o

I'm not using save vars I'm using a method sky showed me with FILE* (For editing configuration settigns)


EDIT:
I'm thinking this:
Code: Select all
map_save (char* filename)
{
    FILE* file = fopen(filename, "w");
 
    if(file != NULL)
    {
        int i, j, k;
        for(i=0;i<TILES_Y;i++)
        {
            for(j=0;j<TILES_X;j++)
            {
                fprintf(file, "%d, ", tilePos[TILES_X][TILES_Y]);
            }
            fprintf(file, "\n");
        }
        fprintf(file, "Mapx:%d\nMapy: %d\ntileWidth: %d\ntileHeight: %d\nGridSize: %d\n(Do not modify the following)\nlayer1:%d\nlayer2:%d\nlayer3:%d\nlayer4:%d\n", mapSizeX, mapSizeY, tileWidth, tileHeight, GRIDSIZE, layerCreated[0], layerCreated[1], layerCreated[2], layerCreated[3]);
        for(k=0;k<250000;k++)
        {
            fprintf(file, "tileAnimPos:%d\ntileAnimPos:%d\ntileAnimPos:%d\ntileAnimPos:%d\n", tileAnimpos[layerCreated[0]][k],tileAnimpos[layerCreated[1]][k],tileAnimpos[layerCreated[2]][k],tileAnimpos[layerCreated[3]][k]);
        }
        fclose(file);
    }
}


after changing the code at the top to this:
Code: Select all
#define TILES_X 500
#define TILES_Y 500

///////////////////////////////////////////////////////////////////////////////

  int
  mapSizeX,              mapSizeY,
  tileWidth,             tileHeight,
  GRIDSIZE,              tilePos[TILES_X][TILES_Y],
  layerCreated[4],       tileAnimpos[4][250000];
 
    //Allows up to 250000 tiles (250*250) to be placed for large, advanced maps.
 
//////////////////////////////////////////////////////////////////////////////
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby skydereign » Thu Jan 03, 2013 4:24 am

Your fprintf is bound to fail. It is always trying to print tilePos[500][500] which doesn't exist. I believe you mean to put the loop integers within the tilePos.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby Hblade » Thu Jan 03, 2013 4:51 am

haha oops. :oops: Forgot about pointers haha... fprintf(file, "%d, ", &tilePos[TILES_X][TILES_Y]); should do the trick if I remember right
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby skydereign » Thu Jan 03, 2013 4:55 am

Actually no. That is only needed for fscanf. The problem is that TILES_X and TILES_Y are defined to be the number of indexes in the array. tilePos[TILES_X][TILES_Y] is out of bounds. You want to replace them with [i][j].
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby Hblade » Thu Jan 03, 2013 4:59 am

Oh! *facepalm*

Wouldn't it be [j][[i] since i represents tileY and tileX Is j?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby Bee-Ant » Sat Jan 12, 2013 4:20 pm

I'm here just to provide another method since learning your code takes time.

First of all, make the tile animation array in global code.
Code: Select all
int TileAnim[500][500];


Next, make the save and load function.
Code: Select all
void LoadTile(char Fname[32])
{
FILE *file 〓 fopen(Fname, "rb"); //let's just use binary for safety
int i, j;
for(i〓0;i<500;i++)
{
for(j〓0;j<500;j++)
{
fread(TileAnim[i][j],sizeof(int),1,file); //read the stored value
CreateActor("tile", "tileanimation", "(none)", "(none)", j*40, i*40, true); //40 is the tile width and height, the tile creation is started from 0,0 coordinate
}
}
fclose(file);
}

void SaveTile(char Fname[32])
{
FILE *file 〓 fopen(Fname, "wb");
int i,j,k;
Actor *check;
char str[32];
for(i〓0;i<250000;i++)
{
sprintf(str,"tile.%i",i);
check〓getclone(str); //get the actor clone
j〓i%500; //get the array column index
k〓i/500; //get the array row index
TileAnim[k][j]〓check->animpos; //store the animpos number
}
for(i〓0;i<500;i++)
{
for(j〓0;j<500;j++)
{
fwrite(TileAnim[i][j],sizeof(int),1,file); //store the values into file
}
}
fclose(file);
}


Next, let's set the tile animpos.
tile > CreateActor > ScriptEditor:
Code: Select all
int i,j;
ChangeAnimationDirection("Event Actor", STOPPED);
i〓cloneindex%500;
j〓cloneindex/500;
animpos〓TileAnim[j][i];


Usage:
Code: Select all
LoadTile("mytile.dat"); //to load
//or
SaveTile("mytile.dat"); //to save


That's all.
Let me know if you have any question :)
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: Uh.. really advanced question o-o saving multi-animpos?

Postby Hblade » Sat Jan 12, 2013 6:14 pm

Wow bee! Welcome back! Haven't seen you in ages! Also, well, thanks! :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron