Saving entities

Blitz3D Forums/Blitz3D Programming/Saving entities

Slomas(Posted 2011) [#1]
Anyone know of way to save all created 3D entities in one go- to then be re-loaded with a 'saved game'? i.e. instead of having to save their info and re-create individually?

Any ideas much appreciated...


Matty(Posted 2011) [#2]
Lots of ways...

assuming you know how to use the writefile/readfile commands, it is not too difficult.

At its most simple the first things you'd need to do is have a name or identifier for each entity, store that, the positions and orientation at the very least...

Here is a cut and paste from some code of mine to show an example:
(straight from a part of one of my games but obviously it won't compile without other functions and types...hope this helps...)



Last edited 2011


Slomas(Posted 2011) [#3]
Thanks Matty-

Your code sample will help me if I do it that way- (out of interest- is that from a playabe game?)

I guess I was being lazy though and wondering if there was a single step cheat- e.g. a chunk of memory where BB stores all the entity info - which I could write/read in one fell swoop...

I could probably use the experience with file handling though...


Matty(Posted 2011) [#4]
Hi Slomas,

Yes it is from a playable game...but one I never bothered finishing (mainly because I've decided to leave writing games for PC and instead writing them for mobile phones and flash instead)


Adam Novagen(Posted 2011) [#5]
wondering if there was a single step cheat- e.g. a chunk of memory where BB stores all the entity info - which I could write/read in one fell swoop

Considering that most games use upwards 100MB of RAM at the very least, that'd be impractical simply because of the sheer SIZE of the save file that'd be generated.


Slomas(Posted 2011) [#6]
I have a few of those too- - there's so much work beyond making something playable for yourself, and then fool-proof for someone else that I never get around to it unless it's paid work-

Adam-

By entities- I mean in the blitz command sense- not all the graphics/textures/sound etc, just the 3D entity info- So I wouldn’t think it would be a whole lot of RAM in this case....

I'm working on a Minecraft inspired theme - couldn't play the game for more than 10 mins without thinking about how to make a better one...

programmers curse!


Charrua(Posted 2011) [#7]
hi
probably the following don't help so much, but if you have the entities properties stored in a Type struct you could save the field's contents in a sigle instruction.

From the Type Help:

A cunning trick for debug purposes, or for saving data from types to a
file, is to use the Str$ command. Print Str$() will print the values of
each field of the type in turn, comma separated, within square brackets,
 e.g. [15,42,"Fluffy",500]. 


Juan


Slomas(Posted 2011) [#8]
Thanks Charrua - that'll definately come in handy

I figured it was a long shot but it's always worth asking here-
great source of knowledge


Slomas(Posted 2011) [#9]
To follow up-

I got the save/load working for all the entities-
but a loaded game runs way slower than the randomly generated one..

I used ClearWorld to remove all old entities, but I'm wondering if this removed the old terrain also? if not- is there a way to delete a terrain from the memory?

I know just creating a new entity with the same name does not delete the old one... so I'm wondering if this is the case with terrains also...


Slomas(Posted 2011) [#10]
OK ClearWorld DOES remove terrains- easy experiment (doh!)
(I should be posting in beginners.....)

Last edited 2011


Yasha(Posted 2011) [#11]
is there a way to delete a terrain from the memory?


FreeEntity works on everything loaded through the 3D engine.


Matty(Posted 2011) [#12]
Should not make any difference to game speed if you load a save file or generate randomly.