Imagine Variables as a box. You can put something in the box, and even add a label to it for clarification of whats in the box.
Lets try it out in this test scenario:
You have your player event set up, putting an Iron Sword in the box (Variable) when the player right-clicks. You label the Box (Name of Variable Item)”ClickSword”, so you can tell the box apart from others. (You dont have to call it that). Afterwards, place a player action: give item into the codespace, and then, instead of entering an iron sword, you can just enter the contents of the box “ClickSword” (Just put the Variable Item in), and it will give you an Iron Sword upon Right-Clicking!
Of course, there are many, many more options you have with variables. Just look through the set variable block. Here’s a couple of examples:
Randomizer:
You pick the set variable to random value option from the set variable block, then enter the variable, after which different items into the chest. (Eg. Wooden Sword, Stone Sword, Iron Sword, etc…). Now, on the base of the previous example, we give the contents of the box (ClickSword variable) to the player, and it will be a random sword picked from the set variable block. [How this works: When setting the variable to the random value, you essentially flip a coin to what you should put in the box. After that is decided in the Set Variable Block, you just have to look inside to find what has been picked!]
Arrow Armada:
Lets try to stick more and more arrows into the player on joining the game. Start out with a player event [Join], then make a repeat block. Set it to repeat X times (e. g. 50), or forever. Then place a control:wait block for 1 tick at the start of the loop. This is so Lagslayer doesnt nuke your game. Okay, now we repeat an event 50 times over after the player joins the game. Lets start putting our box (variable) together. First, we pick a fitting label, like “ArrowsStuck”. We then want to put a number (Representing Arrows Stuck in Player) into the box, and every time the loop is repeated, increase that number (Representing Arrows Stuck in Player) by one. The most fitting set variable block for this is [Set Variable: Increment Number]. We just have to enter the variable, followed by a number (1), and from now on, the loop increases the number by 1. Okay, the hardest part is done. All we have to do now is place a [Player Action: SetArrowsStuck] Block and set it to the variable “ArrowsStuck” we incremented before. After making sure this code is INSIDE the placed repeat loop, you should get more and more arrows stuck in you after joining the game. You can make this faster or slower by increasing the duration of the control:wait block at the start of the loop.