Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | wyi13 |
I write a.tscn, which binds a.gd, and has export variable:
export var test_list = [1, 2, 3]
then initiate 2 a.tscn instances a1, a2. When I clear one’s test_list:
a1.test_list.clear()
a2’s test_list will be cleared too. Are there any docs explain such design? many thanks!
I also encountered this problem, I believe it is a design flaw. There must be some kind of a problem with storing exported variables of type kept as reference ( array, dictionary ). Maybe You can circumvent this problem by adding a child Node to keep your list in his exported variables.
Inces | 2022-07-15 20:31
It also doesnt make sense to me. A quick fix would be to have another var, lets say _test_list
and set it as a copy of testlist
in the _init() method, and then just use that var. Since it is a copy, it wont use the same reference (although it shouldnt do so in the first place, in my non pro opinion). Dont remember how the copy method of arrays is written, but you can look it up!
Pomelo | 2022-07-16 23:52