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

What does a blank mean?

Asked by
emite1000 335 Moderation Voter
9 years ago

I am often seeing an underscore (usually followed by a comma) in scripts. However, I am unable to find information on what this is or what it does. What does _ or _, mean in scripting?

2 answers

Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

This question has already been asked and here is my answer to it


_ is called the underscore.


The underscore is treated by Lua exactly like a letter (a-z, A-Z). It is used in variable names, or on its own (just like you could use x as a variable name, you can use _ as a variable name).


Since spaces aren't allowed in variable names, some styles suggest using the underscore as a space, as opposed to using camelCase or PascalCase: multi_word.


In addition, some built in Lua names use it, including _G, the global table, and the metamethods, which are preceded by two underscores, e.g, __index.


Usually, when _ is used as a variable name, it is to indicate that its value is not important.

Since some functions, like the iterators pairs and ipairs, return two values, you need to give a name to the first value even if you aren't going to use it. Stylistically, the _ is sometimes used to note that.

It is only a stylistic convention and is nothing special, though.

Ad
Log in to vote
-1
Answered by 9 years ago

Well i believe it has 2 purposes... The first purpose is to act as a variable name. The second purpose is _G that is a global variable. I believe that is all there is too _...

Answer this question