FOnline Development > Questions and Answers

serializator.fos - how to use it for loads and saves of world data.

(1/1)

remake:
Hello,

I have question about serializator.fos script. Seriously, I don't understant it well. Can someone explain me this script? I want to know how to use it for loads and saves of world data.

Thank you.
rem

Vice Dice:
It's a wrapper for server side AnyData thingie, you might try to save like this

--- Code: ---void SaveData() // call when needed to save something, i.e in main.fos world save section
{
    Serializator@ serializer = @Serializator(); // create an instance of Serializator
    serializer << DataToSave; // put your stuff into it
    serializer.Save("DataName"); // save it, name is whatever you like
}

--- End code ---
And then load like this

--- Code: ---void LoadData() // call when need to load smth
{
    Serializator@ serializer = @Serializator();  // create an instance of Serializator
    if (serializer.Load("DataName"))             // try to load data, if none found, go for else
    {
       serializer >> VariableToHoldData; // put your loaded stuff into something
       // anything you might need
    }
    else            // do stuff if data was not found
        DoStuffIfNotLoaded();
}

--- End code ---

P.S if those "<<" and ">>" won't work on your revision, try using Set and Get serializator methods ( those are multiply overloaded to fit different data types and their sizes ), it should be equivalent. And yes, you can Set and Get more than 1 "object" with it, even your own types if you teach the wrapper to push it into it's byte buffer and take it back when needed. And you probably want to load stuff in the same order as you saved it.

Navigation

[0] Message Index

Go to full version