Godot Version
`4.4
Question
Hello! I’ve been following this tutorial: click here if you want, and it has been working well for me besides some syntax changes because this was made for 3.x
For my inventory system, I want to be able to press the input, then drag to another slot, and then release to put it in that slot if it is empty or swap it’s location with the one that was just picked up. I have tried using a event.is_released() but the GUI input stops updating while I click and then when I release it goes back to the prior spot it was in.
Relevant code below:
for inv_slot in inventory_slots.get_children():
inv_slot.gui_input.connect(slot_gui_input.bind(inv_slot))
func slot_gui_input(event: InputEvent, slot: SlotClass):
print(slot)
if event is InputEventMouse:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT and event.is_pressed():
if holding_item != null:
if !slot.item:
slot.putIntoSlot(holding_item)
holding_item = null
else:
var temp_item = slot.item
slot.pickFromSlot()
temp_item.global_position = event.global_position - Vector2(10, 10)
slot.putIntoSlot(holding_item)
holding_item = temp_item
elif slot.item:
holding_item = slot.item
slot.pickFromSlot()
holding_item.global_position = get_global_mouse_position() - Vector2(10, 10)```