Scripting Lesson 010: Values and Variables

Well-come, Imagination Tech, and welcome to our tenth scripting lesson. Heck yeah! Double digits! Anyways, we will be talking about variables. Variables are something that you probably see in all-most every script.

Now first, we are going to talk about variables, because it is a crucial part of understanding values. Variable are what values are assigned to. For anyone in an Algebra class, you know that x, y, and z are variables with certain number values like 3, 8, 184, and so on.

Remember when we discussed locals back in the first few lessons. Well that is an example of a variable. It is called a local variable. Let's take this hypothetical line of script that says local part = script.Parent. Now this means that whenever we type part into a script, it will identify as script.Parent. Most scripters use shortcuts like this, as to not have to type huge long lines of script.

Another way to use it is, like in algebra, is to set number values to variables. Take a look at this extremely simplistic and very short CFrame script Domswolf just made.

So as you can see, the x, y, and z variables are global. This means that because there is no local, the values will work for the rest of the script, unless the value is changed. If I were to make a script that does a similar action inside another brick, I have to place _G before it For example, in a server script, type in _G.hi = 'Grounded'. That means that you can use _G.hi from any other server script in the game. Local variables only work inside the loop or if-statement that it was initiated in, and are preferred if you don't want to accidentally ruin another piece of the script. It all depends on what you are trying to do.

Thanks for tuning into this new lesson. See you all next time when we discuss CFraming.

-Domswolf (King of Wrong, just kidding) & Snapcash!