2021-02-23 15:35:03

hi
as title clearly says, i'm searching for a function to convurt string to dictionary to use
please share if you have something that does it
best regards

Thumbs up

2021-02-23 15:40:09

How the hell would you convert a string to a dictionary. A dictionary is a container to store key value pairs. I mean, I guess you could write a parser to take something like "name=Mike" and append it to a dictionary, but why?

Join me in eliminating BGT from the forum.
It's very easy, if you see a topic about BGT, simply don't reply to it.
If you're thinking about creating a topic about BGT, just don't.
Doing these things will cause all such topics to sink to oblivion.

Thumbs up

2021-02-23 15:48:42

Apply the rule of BGT here: Thou must reinvent the wheel.

Sincerely,
Lucas.

Thumbs up

2021-02-23 16:12:06

Hi,

Maybe I’m misunderstanding what you are after, but I would imagine the simplest way to do this is just using BGT’s  built in dictionary method  called set. So it might look something like:

dictionary testDictionary;
string thisIsMyString;
testDictionary.set("key1", thisIsMyString);

the above will have put your string into a dictionary and assigned it to key1. to retrieve the string from the dictionary at a later date you would use the dictionary method get. If you look up dictionary’s in the BGT help documentation you should find all the methods you need  in their to work with BGT’s dictionary’s. again, if I’ve misunderstood what you are after I apologise.

Paul Lemm

Thumbs up

2021-02-23 16:17:34

Well, BGT has functions dedicated especially to that topic, which can be found under the heading serialization, serialize builds a string out of a dictionary and deserialize converts it back into a dictionary. The format of that string however is decided by the serialization functions, so you won't have any influence on that, and the string is most likely not human readable.

Thumbs up

2021-02-23 16:24:08

Yeah serialization makes sense, but it seems like OP wants to create a dictionary from the contents of a string and I'm just like... uh, OK then.

Join me in eliminating BGT from the forum.
It's very easy, if you see a topic about BGT, simply don't reply to it.
If you're thinking about creating a topic about BGT, just don't.
Doing these things will cause all such topics to sink to oblivion.

Thumbs up

2021-02-23 17:07:21

@6
I mean JSON is a thing?  So is key-value pairs?  In Python you can:

dict((i.split("=")[:2] for e in mystring.split(" ")))

Which takes a=b c=d e=f to a dict with a, c, e.

trying to use BGT for this is silly, but the question isn't and I'm not sure why you think it is.

My Blog
Twitter: @camlorn38

2021-02-23 17:24:01 (edited by Lucas1853 2021-02-23 17:31:36)

So for a little bit more of a helpful and detailed response than in post 3, there's code floating around to do this. I wrote something to do it, for example. I think Scrolling Battles might have another algorithm which was either written by Mason or Sam, and it's probably duplicated across some other of Mason's games. So it is possible, and as others have said much easier if you don't need the string to be (easily) digestible by humans. I agree the question isn't silly, but I don't care to hunt down code that does it. Any code that you do find though will be primarily used to deal with configuration files. So in Scrolling Battles, I think you'd look in the sections for loading custom characters (or whatever custom elements that game had, might not have been characters).
Edit: This is mine, but I completely disown it and won't spend too much time helping with it because it's awful and I don't work in BGT anymore. Also I don't think it uses dictionaries in favor of parallel lists, but the concept is the same.
https://raw.githubusercontent.com/carte … d_data.bgt

Sincerely,
Lucas.

Thumbs up

2021-02-24 16:22:32 (edited by manamon_player 2021-02-24 16:24:47)

thanks Hijacker, Lemm, camlorn, and  Lucas1853 for your great helps, I appreciate it

Thumbs up