+1 vote

Hi, I have a scene which includes my inventory. It has 16 tiles where items can be placed.

On the one hand I like to use this scene to add items which the player picks up and on the other hand I like to use the same scene with all the collected items in the shop page.

So that, the user is able to click on the "sell item" button (which is invisible while the scene is the player inventory) to sell the item, and remove it from the inventory.

So the shop page and inventory should be updated allways at the same time (they should be in sync)

What's the best way to do that?

Godot version 3.5
in Engine by (31 points)

1 Answer

0 votes
Best answer

You could use a model-view-controller design, where the items the player has are stored in some internal object (array, children of a node, hash map, etc.) (the model), and then every time a inventory scene is displayed (the view), you dynamically populate the inventory slots to visually represent what's stored in the player's internal inventory data model (the controller).

This way both the shop and inventory don't have to be in sync, since they are only populated when displayed. From the player's perspective they will appear to be in sync. Even if the player's inventory is always visible, the same design can be applied, just update the inventory UI every time the player has his/her inventory data model updated.

by (570 points)
selected by

So if I understood your approach right, I should create 2 instances (shop =1, player inventory =2) of my inventory scene and store the inventory items globally. The if 1 or 2 is opened, I should use my global items array to show what's inside, right?

Exactly. I think that should work

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.