[solved] How do I put an object back in it's original place?

How do I…

In a RPG game, the player picks 12 items out of a 100 possible objects placed in a structured manner.
Those objects are moved into their inventory when the player clicks on any of these items.
When the player clicks on the items in their inventory, how do I make them go back to their original position?

Store the slot position or the original X & Y co-ordinates as instance/object variables on the object that gets added to the inventory.

2 Likes

Thanks @MrMen
It makes sense. Will try to implement it.

Hi @MrMen
Sorry to bother you again.

I tried to implement your suggestion:

In the code, “Item” is the item to be moved to and from inventory.
“slot” is the slot in inventory which would be filled or vacated.

Conditions:

  1. When the mouse is released, the “In_slot” variable checks if the item is in the slot or not.
  2. If it’s not in slot, it puts it in the slot (of inventory).
    This part is working well. only if I comment out the condition 3 below

I seek help in this part which isn’t working:
3. When the “In_slot” is “Yes” (Item is in the inventory slot), then it should read “Original_X” and “Original_Y” and move the item back to this position.

As always, really glad for the great folks to help newbies like me!

The issue is with setting In_slot to “Yes”. When In_slot = 'No", the variable is set to “Yes”. However, a few events further down, it’s checked whether it’s “Yes”, which it will be, and then set to “No”.

What you’re after is an if-then-else statement, which GDevelop doesn’t have. The best solution is to use a second variable (boolean) that keeps track of whether In_slot has changed value, and to ignore the item in the subsequent events.

I hope that makes some sense.

Thanks for the prompt reply @MrMen

To reiterate what you said,

  1. Condition: If variable “In_slot” is “Yes” → Event: Toggle the value of “boolToggle”
  2. Condition: If “boolToggle” is true → Event: Do [some events]
  3. Condition: If “boolToggle” is false → Event: Do [some other events]
  4. Condition: If variable “In_slot” is “No” → Event: Toggle the value of “boolToggle”

Is it correct?
Or did I miss it?

Something along the lines of:

(I’ve left out the left mouse button released event)

1 Like

Thank you so much @MrMen
This makes a lots of sense.
You’ve been most helpful!
LMK if there’s anything I can help you with as well :smiley: