I looked at the documentation for Array.copy
, and I saw this:
If deep is true, a deep copy is performed: all nested arrays and dictionaries are duplicated and will not be shared with the original array. If false, a shallow copy is made and references to the original nested arrays and dictionaries are kept, so that modifying a sub-array or dictionary in the copy will also impact those referenced in the source array.
It seems that calling Array.copy(true)
will only produce duplicates of any nested arrays and dictionaries, not objects. What is happening in your code is that you truly did duplicate choices
into orig_text
, but all the items in orig_text
still point to the same locations as the items in choices
. If you want to have a copy of the original items, you should call choices[i].duplicate()
, where i
is the index of the item. All nodes have a duplicate
method which will return a copy.
This should work for your case.
Here is a small snippet I just thought up (I haven't tested it to see if it works; though it should):
var orig_text = []
for i in range(choices.size()):
orig_text.append(choices[i].duplicate())
Hopefully this helps