• Hey! Register here to create your account, engage with the community, and talk about what is new!

What is a variable? - A Guide to Variables

whatsdusty

Well-known member
Joined
Sep 6, 2020
Messages
68
Reaction score
15
Hello! My name is Enderdust, and in this post I'll teach you how to use variables!
Variables are like boxes. So, lets say we have a box. Now, on the front of this box, is a label. The label tells us what is inside the box.
Now, let's say we put a label on this box that says "Fruit". Then, let's put an apple inside this box.
Then, let's take out the apple and put in an orange.
No matter what is in the box, the label on the front it always the same.
That's sort of how variables work. Each variable has a name (like a label) and a value. The value can change to anything. But no matter what the value is, the name will always be the same.

TIP!
You can set variables using the Set Variable action.

Now, you might be asking,
How is this useful?
Let me explain.

Let's pretend you're making a game where you make and sell bread. You make bread, and you sell it to a man who gives you money for it. Now, you could just give the player an item named "Money" but that would fill up their inventory. So instead, you make a variable. You name the variable "%default money".


TIP!
%default will always be replaced by the player's name. So if I name the variable %default money, and my name is Bob, the variable will be named Bob Money.

Now, using this variable, you will store a number. The number will be the amount of money you have. Whenever you sell some bread, you increment the %default money variable by 5. So if the variable is equal to 10, and they sell bread, it will become 15.

So, that's cool, but how do I detect the value of a variable?
You can do this with the If Variable condition.

There are many different types of variables, like...

  • Numbers
  • Locations
  • Text
  • Sounds
  • Particles
  • Lists
  • Items
Variable Scopes
All variables have a scope. There are three types of scopes:

  • Game
  • Local
  • Save
GAME variables will work anywhere in your code, but when your plot reaches 0 players, all GAME variables will be cleared, and will no longer exist the next time players join your plot.

LOCAL variables will only work in the line of code they were set in. After the line of code finishes, the variable will be deleted. Use this to save variable space when a variable is only needed in a single line of code!

SAVE variables will save even after all players leave your plot. Only set SAVE variables when you need them to save, because there is a 5-7MB limit on SAVE variables.

Variable Limits
All plots have a limit of the amount of variables they can hold.

When making variables, keep in mind:

A plot can only hold up to 500 000 GAME variables.

A plot can only hold up to 5-7 megabytes of SAVE variables.

A list can only hold up to 10 000 values.

Try using these to enhance your plot. See you another time! If you have any questions, feel free to reply below!

- Enderdust
 
Last edited:

RyanLand

Well-known member
Overlord
Joined
Sep 6, 2020
Messages
60
Reaction score
39
You should add a section for variable (idk the name, local, game, saved vars).
 

Requals

Disabled
Overlord
Joined
Sep 8, 2020
Messages
0
Reaction score
148
was the example supposed to be that one game where you buy bread, toast it, then sell it for more money than you bought it for
 
Top Bottom