This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
iRichard's profile picture

Variable variable

Started by iRichard, 10 August 2014 - 09:33 AM
iRichard #1
Posted 10 August 2014 - 11:33 AM
I'm working on a small program, but needs to be variable the variable. (Huh? :huh:/>) This is what I mean:

"..Str2.." = {besteming = "..besteming..", minuut = "..minuut.."}
But this does not work, is there a way that I get this?
MKlegoman357 #2
Posted 10 August 2014 - 12:45 PM
Why do you need it? There might be another and better solution for your problem. If you want to store variables under a string or anything else just use tables:


local myTable = {}

myTable[ "this is a key" ] = "this is a value"

print( myTable[ "this is a key" ] ) -->> this is a value
flaghacker #3
Posted 10 August 2014 - 01:11 PM
If you really need this for whatever reason, you can use:

_G[name] = value
All global values are stored in a global table, _G (Yes _G._G == _G). Therefore you can use all the features of tables on the global environment. More info can be found in the PIL, as always: http://www.lua.org/pil/14.html .

I don't recommend using this, because then you're polluting the global environment. Use your own local table when possible.