Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | _NotH |
So I have code that is similar to something like this:
var dict1 = {"value" : 1}
var dict2 = dict1
func _ready():
print(dict1, dict2)
dict2["value"] += 2
print(dict1, dict2)
The first time, it prints the expected: {value:1}{value:1}
However, after changing dict2’s value, it prints: {value:3}{value:3}
So my question is: why did dict1 also change values if I only wrote for it to happen with dict2?
And more importantly: how do I avoid this from happening?