of     1   

JamMinister
#228400209Sunday, December 03, 2017 9:38 PM GMT

I have this flowchart (this code obviously does not work) for i = 1,10 do local ["item" .. i] = i end for v = 1,10 do print([item .. v]) end So this will print out the numbers 1 to 10 - I want the 'i' for loop to create 10 variables with names "item1", "item2" etc.. with values 1,2 etc.. The 'v' loop will then loop through these 10 variables and print their values. Can this be done? And if so, how?
ScriptBased
#228400460Sunday, December 03, 2017 9:43 PM GMT

Just use a table ? local tab = {} tab[“name”..name] = value
Vulkarin
#228400847Sunday, December 03, 2017 9:52 PM GMT

for i = 1, 10 do getfenv()["item"..i] = i end
ScriptBased
#228400963Sunday, December 03, 2017 9:55 PM GMT

Is it really necessary to use getfenv() for it ?
Rerumu
#228401060Sunday, December 03, 2017 9:57 PM GMT

Do not. Using getfenv sets them as global, not local, and could potentially break things. You should stick to just using tables, as locals are handled at compile-time as opposed to run-time, so you have limited usage of them.
JamMinister
#228402378Sunday, December 03, 2017 10:24 PM GMT

Could you explain a bit more please? local tab = {} local name = 3 tab["name"..name] = 4 print(name3) This doesn't print '4' - how does it work?
ScriptedDonut
#228402441Sunday, December 03, 2017 10:26 PM GMT

libpng
#228402645Sunday, December 03, 2017 10:30 PM GMT

local things = {} things[4] = 1 print(things[4])
JamMinister
#228402862Sunday, December 03, 2017 10:34 PM GMT

Apologies libpng - I know how to call specific values of a table, I'm just still confused how I can use: Just use a table ? local tab = {} tab[“name”..name] = value To achieve my original question
Kiriot22
#228402946Sunday, December 03, 2017 10:36 PM GMT

local tab = {} for i=0,5 do tab["item" .. i] = "something end print(tab["item5"])
ScriptBased
#228402960Sunday, December 03, 2017 10:36 PM GMT

local tab = {} for i = 1,10 do tab[“name”..i] = i end for i = 1,10 do print(tab[“name”..i]) end
JamMinister
#228403203Sunday, December 03, 2017 10:41 PM GMT

Brilliant, cheers guys!
ScriptBased
#228403588Sunday, December 03, 2017 10:49 PM GMT

Cheers

    of     1