Simple routine using a key to toggle move an icon between an inventory rack and an (unseen) reserve.
I can move an item from the reserve to the rack, or vice-versa, but only once!
After that, find_node() returns a null.
Is there some kind of refresh I need to do? The Remote panel shows the icon-nodes being moved around (when it works). Since it works both ways, the code has been validated so now I'm clueless what is going on.
This is test code. I move the node back and forth using a key input in my Main script:
if Input.is_action_just_pressed("6key"):
AddToInventory("batteries")
if Input.is_action_just_pressed("0key"):
RemoveFromInventory("batteries")
func AddToInventory(b):
var moveicon = $IconReserve.find_node(b)
if moveicon != null:
print("added ",b)
$IconReserve.remove_child(moveicon)
$Background/IconRack.add_child(moveicon)
$Background/IconRack.call('FillRack')
else:
print("no ",b," found in reserve")
for i in $IconReserve.get_children():
print(i.name)
func RemoveFromInventory(b):
var moveicon = $Background/IconRack.find_node(b)
if moveicon != null:
print("removed ",b)
$Background/IconRack.remove_child(moveicon)
$IconReserve.add_child(moveicon)
$Background/IconRack.call('FillRack')
else:
print("no ",b," found in rack")
Snapshot of the scenetree. Full project below. This is V 3.5.3.