Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Uses of global variables and what they are? [closed]

Asked by 4 years ago

This question already has an answer here:

"local" in front of variables

I can't find any source to this question, I really need to know the uses of global variables and what they are..

0
I believe "Globals" is just a fancy way of saying function exampleFunction(). Not 100% sure though. niroqeo 123 — 4y
0
What did you look up? I searched this site alone (using the search feature) and I could find a lot of questions about this topic. (Note the question I marked this a duplicate of mostly describes local variables and only slightly describes global variables, but global variables are simpler which is why it only slightly describes it). hiimgoodpack 2009 — 4y

Marked as Duplicate by hiimgoodpack and Filipalla

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
2
Answered by
7z99 203 Moderation Voter
4 years ago
Edited 4 years ago

"Unlike global variables, local variables have their scope limited to the block where they are declared. A block is the body of a control structure, the body of a function, or a chunk (the file or string with the code where the variable is declared)." Source

Essentially, if you declare a local variable in a function, if statement, or loop, you can't use that variable anywhere else. If you declare it out of the function, it can be used anywhere in that script. Global variables can be used anywhere, whether they are declared within a function or not.

To declare a local variable:

local variableName = 12

To declare a global variable:

variableName = 12
0
Thank you, I finally got it! SilentsReplacement 468 — 4y
1
No problem! Good luck on scripting! 7z99 203 — 4y
Ad