[Solved] Move items/tools in inventory window to another slots

How to move 1 item from a certain slot to another? For example from Slot1 to Slot2 etc
What I tried to do is:

  1. Store the information of Slot1 to a variable (temporary variable).
  2. Put information from Slot2 to Slot1.
  3. Put information from temporary variable to Slot2.

Store information from selected slot to temporary variable:


I have a problem when trying to move information from a temporary variable to a target variable:

Because the target variable (name) must be clearly declared, and can’t be modified dynamically.
Allowed: toolBox.page1.row1.column1.name
What I need: toolBox.pageX.rowY.columnZ.name
X,Y,Z value will be based from other variable.

Need help with this or suggestion for another way to move items to another slots.
Thanks.

In the second one that’s underlined in red, it looks like you’re adding a number to a string instead of another string. Either change the variable to a string or use ToString() like you did in your first image.

1 Like

It works but there is still some problem, I hope you can help.
I want to move tool from slot1(‘selected slot’) to slot2 (‘current slot’)

  1. Here is the event to save selected slot to temporary slot.
  2. Current slot to selected slot.
  3. Temporary slot to current slot.

It can move selected slot to current slot but failed to move current slot to selected slot, basically its just swapping the two slots but I only managed to do it half way.


Current slot position is top left with “hoe” in it.
The several text in the pic is to keep track of the variable used.
I want to move the “hoe” to the slot bellow it, currently its still empty thus the text TOOL PAGE1 ROW1 COLUMN1 = 0.

Now I select “hoe” and it become ‘selected slot’ and turn green.


Now i move down and press a button to complete the process, and the slot now become “hoe” and the text TOOL PAGE1 ROW1 COLLUMN1: HOE.
The first problem is the slot above should have become empty, but it still display “hoe” (because it should be swapped).


The second problem is when I select the “hoe”(below) that has been moved from above it, the text TEMPORARY TOOL: should display “Hoe” but instead it display [OBJECTOBJECT].
Sorry if my explanations is bad.
Thanks

I’ll look at the code in a bit. I’m currently using my phone. What code are you using to display the information getting the return of “object”? Sounds like you’re looking at an object not a variable. Maybe you’re missing the final part of the variable like .name

The code for the text object?


I don’t think there is a problem with it, because of the error I only use it to check the value of the variable.

I think the problem is caused by the code no.2 above, it failed to store a string but instead object.

It looks like it should be working but there are a lot of letters and it’s tough to see it all on my phone. I’ll be back in a few.

1 Like

From what you posted; it looks good. Maybe there’s a typo I’m not seeing or the problem is in another section. What does the code look like where you do the moving of the sprites? I would also make sure everything that needs to have a “once while true” condition has one.

Can you post a larger image showing the variable actions together with the preceding lines for context?

The whole process, so much string btw.


What causes both the variables that the arrow is pointing at to be true? And is this line supposed to be a sub-event of the previous line because it doesn’t have any actions.

Edit: I really don’t see anything. You might want to reopen the post or create a new one , so people know this isn’t completely solved.

The first variable will become true if player press Z, and the current position of the slot will become selected slot.
The second variable will become true if Z key is released.

  1. You can move to other slot using arrow keys, and the position of the slot → current slot.
  2. By Pressing Z key(and you are currently didn’t select any slot) the current position of the slot will become → selected slot.
  3. Move the position of current slot using arrow keys to the other slot you want to change the value.
  4. By pressing Z key if you already have a selected slot then the value of the selected slot will be moved to the new slot (or the current slot/ new position)

I thought that empty event will just get ignored by GDev, so it will just become the sub event of Z key press event.

I also think that it should be good not sure why.
Moving a structure Var1 to structure Var2 then move structure Var2 to structure Var3 should be possible right? But somehow when moving structure Var2 to structure Var3 it become object instead, its like it can only be done once.

I dont know about your structure issue. You should be able to swap an infinite number of times.

The empty event will be ignored. I just wanted to make sure it was supposed to be currently empty.

IDK, let’s have a look at the key released.

Z Key release will only set isZKeyReady to true.

I use it to prevent it keep executing events when the key is pressed.
Z key is used to display inventory window, after the inventory window is displayed because Z is still being pressed it will immediately execute another event that’s why I disable Z key after being used and to use Z key again you need to release Z key first.

After looking infinity times, I think you’re missing the GlobalVariableString()… before toolBox in the set to …

2 Likes

And I am infinitely thankful.

1 Like