2017-12-10 00:48:51

Well, the topic name pretty much says it all.
Would it be possible to put objects into dictionaries? I'm asking this because I can't help but think that it would be easy to save and load data if all you had to do is store all the game data in a gameworld object or something, then just pop it in a dictionary, save, then load and override the default with the one you just loaded.
What would happen if you tried?

2017-12-10 03:47:58

You could probably extract the values into a dictionary, however I'm fairly certain you have to use arrays for objects themselves. Some higher level bgt master will probably prove me wrong.
And besides, dictionaries are ridiculously slow and I would not use them for anything more than saving/loading data once per level or something.

2017-12-10 06:20:12

Yes it is possible to store objects into dictionaries, but i don't played much with it so i don't know if it works correctly.

2017-12-10 07:39:37

Yes, you can put objects into dictionaries. Just be sure to use the @ sign, otherwise you'll get a null pointer error.
However, the serialization functions do not work with objects, so you can't use this to save and load directly. I mostly use object dictionaries for movelists and the like.
For saving objects in BGT, you're stuck needing functions to convert objects to and from strings. Yes, for complex objects, this is a pain.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2017-12-25 22:09:52

how do you know the serialization functions don't serialize objects. What do they do? Runtime error? Because surely the dict didn't anticipate having an object in it.

----------
An anomaly in the matrix. An error in existence. A being who cannot get inside the goddamn box! A.K.A. Me.

2017-12-26 02:33:43

Try it. You'll find out exactly what happens.
I think the serializer would give you an empty string back if you put things in there that can't be directly serialized.
The easiest way to serialize collections of objects is to add a serialize method to your objects which takes a handle to the target dictionary and some kind of identifier (which could be simply the object's position in some actor array).
That way you can right stuff like:
void serialize(dictionary@ destination, int id)
{
destination.set("char"+id+"_health", health);
destination.set("char"+id+"_atk", attack);
//...
//...
}
The same needs to be done for deserialize. This avoids having to write string parsing functions.

Official server host for vgstorm.com and developer of the Manamon 2 netplay server.
PSA: sending unsolicited PMs or emails to people you don't know asking them to buy you stuff is disrespectful. You'll just be ignored, so don't waste your time.