Is this even possible? For example say I have this code
1 | local part 1 = "hi" |
2 | local part 2 = "hello" |
3 |
4 | for i = 1 , 2 do |
5 | print ( "part" ..i) |
6 | 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:
1 | local tbl = { |
2 | [ "part1" ] = "hello" ; |
3 | [ "part2" ] = "hello2" ; |
4 | [ "part3" ] = "hello3" ; |
5 | } |
6 | for i = 1 , 3 do |
7 | print (tbl [ "part" ..i ] ) |
8 | end |
kingdom5 also suggested this as an option. However, it's better to use a table.