aight here it comes:

I have a game called gravball (as visible in the showcase 1 thread). In the game you have an editor. In the editor you can compose your own level with several objects such as planets, stars, launch platforms, exitgates, electrons etc etc.

If we exit the editor, you will get a question if you want to save the level you made. You press 'yes' and the saveGame() function will be called. So that's where Im stuck at.

The gameSave will search throughout all the entities searching for objects with the flag my.saveable set to on:

Code:

define SAVEABLE, FLAG2;
[...]

function setEnergyDot(&pos) {
if (!me) {return;}

you = ent_create ("electron1.tga", vector (pos[0], pos[1], pos[2]), energyDot);

[...]
you.NAME = "energyDot";
you.SAVEABLE = ON;
you.FACING = ON;
you.LIGHT = ON;
[...]

}



So now that we have found an entity out of the few that have to be saved, we have to store it. So far my idea was to put it in a text file like this:

Code:

function saveGame(name) {
filehandle = file_open_write(name);

you = ent_next (null);

while (you) {

if (you.saveable == off) {
you = ent_next (you);
continue;
}

//name
file_str_write (filehandle, "ent(");
file_str_write (filehandle, you.NAME);

//position
file_str_write (filehandle, ",");
file_var_write (filehandle, you.x);
file_str_write (filehandle, ",");
file_var_write (filehandle, you.y);
file_str_write (filehandle, ")");

wait(1);
}

file_close (filehandle);
}



This will probably result in a textfile with the content:

ENT(energyDot,50,22)

Now the file is full of those saved entities, which would supposedly look like this:

ENT(energyDot,50,22)ENT(energyDot,55,28)ENT(planet,10,72)ENT(star,500,632)ENT(asteroid,150,433)ENT(launchpad,214,311)...etc...etc...

But to load this, we need to get the whole string out of the file again, search for the word "ENT(", clip the string from there, search for the closing ")", truncate until there, and you have the name, x and y position basically retrieved. Some more truncating and clipping and you're done. But this is alot of work, and not such a great method to use. So I was hoping it could be done in a different way.

Last edited by Jostie; 08/02/07 20:15.

Click and join the 3dgs irc community!
Room: #3dgs