|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Mon May 25, 2009 3:10 am
LUA ADVANCED Create a Variable name based on the value of a variable |
I am writing a script in LUA and I need to be able to create a Variable with the Name of the value of another variable.
so I have:
lastroom = "r" .. zs.func.roomvnum()
so my lastroom variable has a value of r11372, so I need to be able to create a variable with the name of r11372 by referencing the variable lastroom.... I hope there is somebody that knows how to do this, I have been searching and searching google for examples and have not been able to find one yet. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 25, 2009 5:07 am |
_G[lastroom] = "whatever"
_G is the global table, it contains the root namespace - so _G.something == something. So _G[variable] will reference whatever the variable contains. |
|
|
|
xekon Apprentice
Joined: 11 Oct 2007 Posts: 154
|
Posted: Mon May 25, 2009 5:18 am |
sweet thanks, EXACTLY what I needed, how did you figure it out, or where did you read about it? Wondering if you know of some good documentation that I missed.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 25, 2009 5:40 am |
I suspect it was part of Programming in Lua, which is available free online (though that version is partially out of date). But you just kinda osmose this sort of info ;)
|
|
|
|
|
|