Using variables in gui.get_node? (SOLVED)

So, I’m trying to expand my knowledge by making a hot bar with items. I currently have a system that I think will work, where it checks the previous inventory array with the new inventory array, detecting changes. I’m using a for loop for this, but I plan on having 9 separate slots that I need to modify, and I don’t know how I’d change the item sprite for a specific slot. I’ve tried setting a slot array where all the slots are set by something like this;

for i=1,9,1 do
    slots[i] = gui.get_node("slot", i,)
end

but that only reads it as if it was

slots[i] = gui.get_node("slot")

Do I just have to manually set each index in the array to the node? Or is there a way I can do it similar to this?

Assuming the nodes are named slot1, slot2, etc., you can use string concatenation like so:

for i=1,9 do
    slots[i] = gui.get_node("slot" .. i)
end

Thank you, worked amazing! I tried that, but I thought it was 3 dots instead of 2.

1 Like