kino Posted August 8, 2013 Share Posted August 8, 2013 how to create link on var or enum e.g :factinfo[factnum][1]==factinfo[factnum]["rang1"]? Link to comment
bandi94 Posted August 8, 2013 Share Posted August 8, 2013 how to create link on var or enum e.g :factinfo[factnum][1]==factinfo[factnum]["rang1"]? if you mean a table then. local factinfo={} factinfo[factnum]={} --then it's ready to use like. for i=1 , 10 do factinfo[factnum][i]="rang"..i end Link to comment
kino Posted August 9, 2013 Author Share Posted August 9, 2013 how to create link on var or enum e.g :factinfo[factnum][1]==factinfo[factnum]["rang1"]? if you mean a table then. local factinfo={} factinfo[factnum]={} --then it's ready to use like. for i=1 , 10 do factinfo[factnum][i]="rang"..i end no, see exmple psevdo lua code factinfo={} > factinfo[factnum]={} > for i=1,10 do factinfo[i]={} end > factinfo[1][1]=3.14 > print(factinfo[1][1]) 3.14 > print(factinfo[1]["data1"]) 3.14 > factinfo[1]["data"]=6 > print(factinfo[1][1]) 6 Link to comment
Vector Posted August 9, 2013 Share Posted August 9, 2013 you can achieve what you want with metatables and metamethods. local factinfo={} setmetatable (factinfo, { __index = function(theTable, index) if type(index) == "number" then return theTable[factnum]["rang" .. tostring(index)]; end; return theTable[factnum][index]; end, __newindex = function(theTable, index, value) if type(index) == "number" then rawset (theTable[factnum], "rang" .. tostring(index), value); else rawset (theTable[factnum], index, value); end; end }); now, you can do this.... factinfo [1] = 56; print (factinfo["rang1"]); -- 56 print (factinfo[1]); -- 56 factinfo["rang2"] = 5; print (factinfo[2]); -- 5 print(factinfo["rang2"]); -- 5 print(factinfo[factnum]["rang2"]); -- 5 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now