Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Klagsam |
I have a scene called LandTile - which is my Template. My GameMap is made of several scenes of LandTile which inherit from the original scene (the template) with this piece of code:
func create_map(width : int = size.x, height : int = size.y ): #a 2D Array with a LandTile in each cell
var a = []
for x in range(width):
a.append([])
a[x].resize(height)
for y in range(height):
var lt = load("res://LandTile.tscn")
var lti = lt.instance()
add_child(lti)
and everything works as expected so far.
Now I added two variables to LandTile:
var harvest : Dictionary
var defense : int
Then I have 2 functions:
func set_defense (amount : int):
if amount > 0 :
defense = amount
func set_harvest(resEnumArray : Array, amountArray : Array):
if resEnumArray.size() == amountArray.size():
for i in range (resEnumArray.size()):
harvest[resEnumArray[i]]=amountArray[i]
Now if I call
specialLandTile.set_defense(2)
I get what i expect: just specialLandTile has a defense value of 2, all others have 0.
However: If i call specialLandTile.set_harvest([1,2,3][3,3,3])
I do get {1:3, 2:3, 3:3}
on ALL my landTiles, i.e. if I add to an empty Dictionary the way I do it, the Dictionary is changed in all instances. Is that supposed to be like that or is it a bug?
And: Has anybody an idea for a workaround?