Blackvoxel > General Discussion

Saving variables

<< < (2/3) > >>

olive:

--- Quote from: Qon on October 25, 2013, 01:41:47 am ---Answer: You simply use GetQuantity(32768) to get the name of the save file before each save/load. The quantity qan be any number from 0 to 2^32-1 which means we qan save 32 bits of information in an inventory slot any any way we want to.

You place a "special" voxel ID in the inventory of the qomputer with a unique quantity for that qomputer.
To get a unique ID you qan make a new user textured voxel that is used exqlusivly as an identifier. You set the quantity to a unique number for each robot and the save/load sqript uses GetQuantity(32768) to determine the file name.

32768 is the id of user textured voxel 1.
Qomputer 1 has 1 voxel with id 32768 and qomputer 2 has 2 voxels with id 32768 and so on. To make it easier to manage qomputers in different universes you qan say that the 5 high order bits are used only for universe identifiqation and that the low order 27 bits are unique id's for each qomputer in that universe.
So the number of voxels stored in a qomputer should be

--- Code: ---ID = (U << 27) | N //ID = U*pow(2,27) + N
--- End code ---
where U is the universe number-1 you are in and N is a unique (in that world) identifying number that is at most 2^27-1 (more than you need, you qan have a qube of size 512x512x512 of just qomputers in each universe).
and you name each file ID.save or something.

--- End quote ---

Cool method, that's a clever idea  :)

olive:

--- Quote from: Toupie on October 24, 2013, 01:46:09 pm ---Now it's possible to save variables between game save/load with the following code.


--- Code: ---Len <- 1;
Dir <- 0;
Moves <- 0;

function Voxel_Load()
{
    try {
        dofile("save.nut");
        remove("save.nut");
    } catch(e) {}
}

function Voxel_Unload()
{
    local s;
    s = compilestring(format("::Moves<-%d;\n::Dir<-%d;\n::Len<-%d;\n",Moves,Dir,Len));
    writeclosuretofile("save.nut",s);
}

--- End code ---

But there is not enough information available to the script to distinguish different robots apart or different universes.

I was thinking I could save the variables for a script in it's Voxel_Unload function. I need to have a way to separated several programmable robots that all run the same script apart. So I thought their x,y,z position should do. But those are not available in the Voxel_Load and Voxel_Unload.
I also need to separate the saved variables from different universes, but there is no way of knowing what universe we are in.
There should probably also be a way for a script to read it's program number. (In case you have copied or renamed it)

I also have trouble identifying if Voxel_Load was called because the robot was placed in the world, loaded, or had it's program changed. I really only want to load stored variables when the robot is loaded into the world, not when it is first placed, or had it's program changed.

All in all, it would probably be better if there was a specific blackvoxel function that handled the saving and loading of variables that a script could use.

--- End quote ---

Yep, we agree. That would be a good idea to provide a kind of serial number for the robot.  And something like getting a directory and path to save the files for a particular game.

olive:

--- Quote from: Toupie on October 25, 2013, 12:13:21 am ---...
I'm still at a loss to why squirrel is used instead of lua. The trouble the author of squirrel had with lua garbage collection is long since fixed in lua.

--- End quote ---

Why we didn't choosed Lua ? The answer is simple : Because Lua does not have a C-like syntax.

Most languages used by programmers today are C-Syntax based: Php, Java, C#, C++, Javascript are C-Syntax based.

A video game can be a fantastic tool for learning programming. That's why we think the language used for Blackvoxel would have to be as close as possible to the syntax of real "useful" programming languages. We think that's an important choice.

We made the choice of Squirrel after hesitations with AngelScript. We choosed Squirrel for technical reasons. Finally, we also found that Squirrel is used for some big "AAA" games (and even if it wasn't the first criteria), that's finished to convince us.

Yes there are things that could be improved in Squirrel. But as far as we looked, that's true for all "integrables" languages we have found. They have all their own strength and weaknesses.

The Blackvoxel Team

Toupie:

--- Quote from: Qon on October 25, 2013, 01:41:47 am ---Answer: You simply use GetQuantity(32768) to get the name of the save file before each save/load. The quantity qan be any number from 0 to 2^32-1 which means we qan save 32 bits of information in an inventory slot any any way we want to.

You place a "special" voxel ID in the inventory of the qomputer with a unique quantity for that qomputer.
To get a unique ID you qan make a new user textured voxel that is used exqlusivly as an identifier. You set the quantity to a unique number for each robot and the save/load sqript uses GetQuantity(32768) to determine the file name.

32768 is the id of user textured voxel 1.
Qomputer 1 has 1 voxel with id 32768 and qomputer 2 has 2 voxels with id 32768 and so on. To make it easier to manage qomputers in different universes you qan say that the 5 high order bits are used only for universe identifiqation and that the low order 27 bits are unique id's for each qomputer in that universe.
So the number of voxels stored in a qomputer should be

--- Code: ---ID = (U << 27) | N //ID = U*pow(2,27) + N
--- End code ---
where U is the universe number-1 you are in and N is a unique (in that world) identifying number that is at most 2^27-1 (more than you need, you qan have a qube of size 512x512x512 of just qomputers in each universe).
and you name each file ID.save or something.

--- End quote ---

But doesn't that mean the user will have to manually add those blocks to the robot every time it is placed in the world? So it's up to the user to make sure the id is unique? Does not sound very appealing to me.

If I just get access to the universe number I can save it as Universe_PosX_PosY_PosZ, that will make it unique since there can only be one robot at one place in the same universe. Or alternatively, get the path to the current universe save directory, the PosX_PosY_PosZ will be unique in that path.

Qon:

--- Quote from: Toupie on October 25, 2013, 06:57:01 pm ---But doesn't that mean the user will have to manually add those blocks to the robot every time it is placed in the world? So it's up to the user to make sure the id is unique? Does not sound very appealing to me.
--- End quote ---
Yes, exactly. I said that it was inqonvinient. It's a workaround to make it possible while waiting for proper tools.
You qould use the qoordinate and save Universe number (0-19) only in the inventory to make it somewhat easier. The question is: do you want to save universe number in the sqript or in the inventory? Choose what's easiest.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version