I have a variable, and a string with the variables name. Is it possible for me to find the variable with that name, through code ( dont want to use eval(), unless i have too)
If you put those variables in a table, then you can get the variable's name through code, like so:
1 | local Var_Table = { |
2 | A = true ; |
3 | B = 20 ; |
4 | C = "Hello World!" ; |
5 | } |
6 |
7 | print (Var_Table [ "A" ] ) --prints "true" |
8 | print (Var_Table [ "B" ] ) --prints "20" |
9 | print (Var_Table [ "C" ] ) --prints "Hello World!" |
Hope this helped!
You can use the getfenv
function to return the current environment in a table.
1 | local String = "MyVariable" |
2 | local Variable = getfenv () [ String ] |
3 | if Variable then |
4 | print (Variable) |
5 | end |
Note that in newer versions of Lua (Which Roblox does not use) you get the environment from the _ENV
variable and not getfenv