-Reference: Using Godot 3.02
Hi guys, I devloping a inventory and stumbled across another problem. I create a button to each item in my array, with the following code:
var UPDi = 0
while UPDi < InventoryItems.size():
var newInventoryItemButton = Button.new()
newInventoryItemButton.set_text(str(InventoryItems[UPDi].Name))
InventoryListVBox.add_child(newInventoryItemButton)
UPDi += 1
I simply want to define automatically functions inside the new buttons, like:
ItemUse(): #Use item and removes it.
ItemDrop(): #Remove item and create a instance near the player.
But I want to define these one time, and apply them in my code. Would be like:
var UPDi = 0
while UPDi < InventoryItems.size():
var newInventoryItemButton = Button.new()
newInventoryItemButton.set_text(str(InventoryItems[UPDi].Name))
InventoryListVBox.add_child(newInventoryItemButton)
UPDi += 1
#WHAT I WANT TO ACHIEVE
newInventoryItemButton.ApplyMagicAutomaticFunctions()
How I would do that? I am trying for the first time to wrap my head around inheritance, but can't understand it.
Your help is appreciated!
TBCK