Page 1 of 1

copyMap does not copy containing maps.

Posted: 25 May 2016 16:32
by bichlepa
I'm trying to use maps which are inside other maps.

I have a map named "global_gamestate". The map contains other maps e.g. "red". So I can get or set a value using

Code: Select all

global_gamestate["red"]["points"]
Now my problem: I want to make a copy of "global_gamestate", but if I use the function copyMap, it does not copy the submaps.

Re: copyMap does not copy containing maps.

Posted: 25 May 2016 19:20
by Martin
Yes, copyMap creates a flat copy (shallow copy). You can either copy the maps within the map manually by looping over the main map or you could temporarily convert the map to JSON and back.
A script could look like this:
map = newMap();
...
copy = fromJSON(toJSON(map));

Regards,
Marti