Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: 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.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: 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 ;)
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net