Hi all experts,
I would like to process String as a variable name and print something out. But I fail. Here is my example:
local Animal = “Frog and Horse and Chicken”
local Fruit = “Apple and Orange”
local Food = “Vegetable and Meat”
local objectTable = {“Animal”, “Fruit”, “Food”}
print ( objectTable[1] ) --> it will output: Animal, but what I need is to output “Frog and Horse and Chicken”
Would it be possible to treat <<value of objectTable[1] >> as a variable name: Animal to print out: “Frog and Horse and Chicken” instead of printing out: Animal
I know it is not a good programming practice. But I really need this to happen.
Many thx
Best regards,
Frankie
It is
local objectTable = {Animal, Fruit, Food}
It is similar to
objectTable["Animal"]=" my text ... "
local tbl\_indexed = {"Frog and Horse and Chicken", "Apple and Orange", "Vegetable and Meat" } local tbl\_keyed = { animal = "Frog and Horse and Chicken", fruit = "Apple and Orange", food = "Vegetable and Meat" } print(" tbl\_indexed index #2 = " , tbl\_indexed[2]) print(" tbl\_keyed Food key = " , tbl\_keyed.food)
It is
local objectTable = {Animal, Fruit, Food}
It is similar to
objectTable["Animal"]=" my text ... "
local tbl\_indexed = {"Frog and Horse and Chicken", "Apple and Orange", "Vegetable and Meat" } local tbl\_keyed = { animal = "Frog and Horse and Chicken", fruit = "Apple and Orange", food = "Vegetable and Meat" } print(" tbl\_indexed index #2 = " , tbl\_indexed[2]) print(" tbl\_keyed Food key = " , tbl\_keyed.food)