I have this code that basically replaces a "Unit" list value in EnemyUnits dic with a list value from EnemyDic. And then it takes "HP", "Aim", "Def" values in newly replaces list and appends them at the end (for future use as base values).
var EnemyUnits = {"Unit7" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit8" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit9" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit10" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit11" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit12" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit13" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit14" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"],
"Unit15" : ["Name", "HP", "Aim", "Def", "Status", "Lvl"]}
var EnemyDic = {"0" : null,
"1" : ["Goblin", 70, 50, 50, [], 1],
"2" : ["Orc", 100, 60, 90, [], 1],
"3" : ["Skeleton", 130, 30, 150, [], 1],
"4" : ["Bear", 170, 90, 150, [], 1]
}
func populate_enemy_nodes():
for i in 9:
#gets a value from UnitListNum that is a list of 9 generated numbers*
var UnitListValue = UnitListNum[i]
#based on a number from UnitListNum takes a list value from EnemyDic and replaces Unit* with it in EnemyUnits*
EnemyUnits["Unit"+str(7+i)] = EnemyDic[str(UnitListValue)]
if EnemyUnits["Unit"+str(7+i)] != null:
EnemyUnits["Unit"+str(7+i)].append(EnemyUnits["Unit"+str(7+i)][1])
EnemyUnits["Unit"+str(7+i)].append(EnemyUnits["Unit"+str(7+i)][2])
EnemyUnits["Unit"+str(7+i)].append(EnemyUnits["Unit"+str(7+i)][3])
print(i)
print(EnemyUnits.keys()[i])
print(EnemyUnits["Unit"+str(7+i)])
print(EnemyDic)
But for some reason not only EnemyUnits lists get appends but also EnemyDic lists. And EnemyDic occurs only once in my code outside of var declaration.
0
Unit7
[Orc, 100, 60, 90, [], 1, 100, 60, 90]
{0:Null, 1:[Goblin, 70, 50, 50, [], 1], 2:[Orc, 100, 60, 90, [], 1, 100, 60, 90], 3:[Sceleton, 130, 30, 150, [], 1], 4:[Bear, 170, 90, 150, [], 1]}
1
Unit8
[Orc, 100, 60, 90, [], 1, 100, 60, 90, 100, 60, 90]
{0:Null, 1:[Goblin, 70, 50, 50, [], 1], 2:[Orc, 100, 60, 90, [], 1, 100, 60, 90, 100, 60, 90], 3:[Sceleton, 130, 30, 150, [], 1], 4:[Bear, 170, 90, 150, [], 1]}
2
Unit9
[Goblin, 70, 50, 50, [], 1, 70, 50, 50]
{0:Null, 1:[Goblin, 70, 50, 50, [], 1, 70, 50, 50], 2:[Orc, 100, 60, 90, [], 1, 100, 60, 90, 100, 60, 90], 3:[Sceleton, 130, 30, 150, [], 1], 4:[Bear, 170, 90, 150, [], 1]}
3
Unit10
[Orc, 100, 60, 90, [], 1, 100, 60, 90, 100, 60, 90, 100, 60, 90]
{0:Null, 1:[Goblin, 70, 50, 50, [], 1, 70, 50, 50], 2:[Orc, 100, 60, 90, [], 1, 100, 60, 90, 100, 60, 90, 100, 60, 90], 3:[Sceleton, 130, 30, 150, [], 1], 4:[Bear, 170, 90, 150, [], 1]}
etc
I assume that somewhere here EnemyUnits["Unit"+str(7+i)] = EnemyDic[str(UnitListValue)] EnemyDic gets the same "appended" values as EnemyUnits for some reason. How do I fix this?