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

Is there a way to make variables with alphanumeric symbols like . / ; etc?

Asked by 9 years ago

How do I use them?

I want to use variables in that way, or define them

0
DON'T use variables with symbols. It's pointless and will decrease readability. Perci1 4988 — 9y
0
"alphanumeric" means "alphabet + numbers" which is exactly what . and / AREN'T. BlueTaslem 18071 — 9y

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

You can achieve the effect you want using a Table, but there is no way, that I know of, to use them as variable names directly:

local vars = {}

vars["1!#%W!~!#^"] = -11
vars["Bloo #11"] = true

Also, those aren't "alphanumeric symbols". They're just symbols. Alphanumeric symbols are just the numbers 0 to 9, and the letters A-Z and a-z. Nothing more.

Edit: I don't know why you think you need to use extraneous symbols for defining variables, but whatever you do, be careful with the '\' character. It is used for "escaping" special characters in Strings, and will cause errors if used improperly. To get around this, you have to use the string-literal constructor (as opposed to the quotation marks):

local vars = {}

vars[ [[
A fancy string!!!
///////////\\\\\\\\\\\\\\

All of the whitespace in this string is preserved,
except for the first character if it is a newline, which it is here.

\' \" \[ \] Escape sequences are ignored.

-- You can't make Lua comments!

The tail newline is *not* ignored,though...
]] ]
Ad
Log in to vote
1
Answered by 9 years ago

There is a way, but the only way to access them is to index them through their function environment (getfenv())

getfenv()["!@#"] = "this is a global variable"

print( getfenv()["!@#"] ) --> this is a global variable"

print ( !@# ) --> error

Answer this question