+2 votes

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?

in Engine by (17 points)

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

1 Answer

0 votes

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.

by (1,248 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.