Resize on 1 exported array does the same for the other

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Floppy

In my inventory system, I have a toolbelt and an inventory seperately. They work pretty much the same, except for a few minor changes. I decided to add them both in the same script for convenience.

So right now, I have this code:

export var inventory = Array() setget set_inventory, get_inventory
export var toolbelt = Array() setget set_toolbelt, get_toolbelt

func _init():
    inventory.resize(18)
    print(inventory.size())
    toolbelt.resize(6)
    print(inventory.size())

This will first output the following below.

18
6

Which of course is incorrect, as both log the same thing. If I remove the export in front of both variables, it does work. But from my testing, the method ResourceSaver.save, which I use to save the inventory, only seems to save exported members.

How can I fix this issue?

You haven’t shown your setters and getters. Is it possible you copy and pasted and forgot to change the member variable they use?

Bernard Cloutier | 2020-10-19 15:13

:bust_in_silhouette: Reply From: Bernard Cloutier

Disregard my comment, I’ve just tried it and it looks like a bug.

Anyways, I’ve never seen the export keyword used without arguments. So I tried it like so:

export(Array) var inventory
export(Array) var toolbelt

func _init():
	inventory.resize(18)
	print(inventory.size())
	toolbelt.resize(6)
	print(inventory.size())

And now it works as expected. No clue why both vars end up pointing to the same array in your example.