Is this even possible? For example say I have this code
local part1 = "hi" local part2 = "hello" for i = 1, 2 do print("part"..i) end
So basically I want it to print the Variable but that will literally just print "part1" and "part2". How can I make it print "hi" and "hello"??
There is not a really simple way to do this in Lua. Your best option is to have a table with string indices.
Here's an example:
local tbl = { ["part1"] = "hello"; ["part2"] = "hello2"; ["part3"] = "hello3"; } for i = 1, 3 do print(tbl["part"..i]) end
kingdom5 also suggested this as an option. However, it's better to use a table.