Map and list copying shallow vs Deep.

Fool

  • Posts: 88
So I'm saving a map object into a list during an event, essentially recording the x and y tile location of each mouse event.
However what I'm finding in the process is that the x and y of each tile location are all the same for every entry in the list.
So my 'tile' attribute which I'm using as an intermediate variable for my x and y values, before storing it in my list--when I change my tile attribute, ALL copies of it in the list are ALSO changed.

From what I could find in the manual and online, the problem is due to Stencyl using shallow copying. I found the 'copy map/list' blocks but according to what I read, these only do shallow copies as well.

I take it I need to use the 'new map' block each time I store a new entry, and then modify the entry itself after it is already stored in the list, or is there a better method that I'm not aware of?

I'm grateful for any help and insight that anyone reading this can provide. Thanks.

letmethink

  • *
  • Posts: 2545
I'm fairly sure I have a deep copy function saved somewhere that I can drag out and wrap if you want it.
~Letmethink

Fool

  • Posts: 88
Yeah if you got the time, I'd be very thankful.

letmethink

  • *
  • Posts: 2545
Here's a behaviour with a single custom block that should work for you. It is a png file but you can import it into Stencyl and it will be recognised as a scene behaviour. If it doesn't work, I'll look into it as I haven't used it with maps before, just lists.
~Letmethink