copyMap does not copy containing maps.

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
bichlepa
Posts: 148
Joined: 04 Mar 2014 18:29
Location: Germany
Contact:

copyMap does not copy containing maps.

Post by bichlepa » 25 May 2016 16:32

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: copyMap does not copy containing maps.

Post by Martin » 25 May 2016 19:20

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

Post Reply