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

is local importand by every variable?

Asked by 3 years ago

so when im doing my tutorial ( dev king tutorial) he said its better to set everywhere by every variable "local" is it important to set by every variable "local"?

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

It's generally better to use local variables than using global variables for the simple reason that because the local variables use less performance. As said in the devforum, because global variables and functions must be accessed by a hash lookup, they can be expensive to use in terms of performance. In fact, a global variable accessed in a time-critical loop can perform 10% slower (or worse) than a local variable in the same loop. So basically your script runs better. Still, you still need to know about scopes, because, as you may already know, a local variable declared in a function will have a nil value outside this function

Ad

Answer this question