• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

String Parsing : to ds_map

Mert

Member
Hi. I'm using a service that returns me a string of a map. An example is;

Code:
{field={subfield1=fallback, subfield2=nothing}, field2=aaa, field3=185, field3={subfield1=test, subfield2=no}}
Edit : subvalues can have its own subvalues too.

What I want to do is to convert this string into a ds_map. Notice that some fields have single value while some others have their subvalues. This pretty much looks like a JSON though.

My mind is stopped right now to be honest :D
Any suggestions ?
 
Last edited:
I would just go through the string character by character and when you hit an equal sign, go back and get the string on the left (until whitespace or '{') to use as the key (of the main ds_map), and if the right side of the equal sign is a set (starts with '{'), then create a nested map. Otherwise, just grab the value on the right, and save that with the key on the left.

Best way would probably be to make a function that works recursively.
 
Top