+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():

This will first output the following below.


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 (16 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():

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

by (1,112 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 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 webmaster@godotengine.org with your username.