`extends Node2D
const SlotClass = preload("res://Inventory/Slot.gd")
@onready var inventory_slots = $GridContainer
var holding_item = null
func _ready():
for inv_slot in inventory_slots.get_children():
inv_slot.connect("gui_input" , self , "slot_gui_input", [inv_slot])
func slot_gui_input(event: InputEvent, slot: SlotClass):
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT & event.pressed:
if holding_item != null:
if !slot.item: # Place holding item to slot
slot.putIntoSlot(holding_item)
holding_item = null
else: # Swap holding item with item in slot
var temp_item = slot.item
slot.PickFromSlot()`
temp_item.global_position = event.global_position
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()
func _input(event):
if holding_item:
holding_item.global_position = get_global_mouse_position()`
I was following a tutorial for an inventory, the tutorial used Godot 3. whilst I use Godot 4. This is the code that is giving the error ( < inv_slot.connect("gui_input" , self , "slot_gui_input", [inv_slot]) >, is giving the error) Error
- Line 9: Too many arguments for "connect()" call. Expected at most 3 but received 4.
- Line 9: Invalid argument for "connect()" function: argument 2 should be "Callable" but is "res://Inventory/Item/Item.gd".
- Line 9:Cannot pass a value of type "String" as "int".
- Line 9: Invalid argument for "connect()" function: argument 3 should be "int" but is "String".