So arrays and dictionaries are both actually objects. When you say:
a = [1,2,3]
b = a
What actually happens is that b becomes a reference to the array itself, not a copy of one. What you want to do is use duplicate()
, like:
a = [1,2,3]
b = a.duplicate()
One thing to keep in mind is that duplicate()
, by default, will not duplicate arrays inside of other arrays. So if you did something like:
a = [[1,2,3], [4,5,6]]
b = a.duplicate()
b.append(7)
print (a)
print(b)
you get
[[1,2,3], [4,5,6]]
[[1,2,3], [4,5,6], 7]
because only the outer array would get duplicated. In order to duplicate every single array or dictionary, all the way down, you need to run a.duplicate(true)
Here's the docs on duplicate: https://docs.godotengine.org/en/3.1/classes/class_array.html#class-array-method-duplicate