I wanna set variable A to = var B, and var B to have the value A
What is the expected result
basically im working on item swapping thingy so when i set the 1st variable, and the second they should “swap” their values? maybe. Im using local variables to store their values but it still doesnt work
What is the actual result
Sometimes it just gets set to 0 or doesnt work at all, really buggy
swap[0] stores the first picked slot’s values, and swap[1] holds thhe values of the second slot. __SlotBasedInventory[0].hotbar[slot number here].name will return the name of the item in the slot, while __SlotBasedInventory[0].hotbar[slot number here].quantity will return the quantity (which you can also get by: SlotBasedInventory::SlotQuantity("hotbar",slot number here))
Any idea why this doesnt work?
Project files (optional)
Insert a minimal game showing your issue in a .zip or .rar.
That’s the problem. Local variables only exist for the scope of the event they’re declared in.
What I mean by that is the local variable only exists in the red section below. Once the event processing falls outside of that, the variable is destroyed and doesn’t exist.
Every time GDevelop reaches the event that the local variables are declared in, the local variable is created and set to whatever their default value is. In your case, it an empty array.
It can be done with just 2 variables and an XOR used 3 times. Very useful in the days of 8 bit machines and 4K demos when memory was a premium, but not so much now-a-days:
say A = 51 and B = 32.
A = A xor B
A => 19
then
B = A xor B
B => 51
and finally
A = A xor B
A => 32