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?

Thumbs up


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.

Thumbs up


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.

Thumbs up


Yes, you can put objects into dictionaries. Just be sure to use the [ a-t ] 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.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up


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. Neo, without Morpheus. A being who cannot get inside the goddamn box! A.K.A. Me.

Thumbs up


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([email protected] 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.

Proud to be the official hosting provider for http://www.vgstorm.com!

Thumbs up