Woops, I think topic title should be “Dynamically accessing table names”
sorry, newbie here.
Is it possible in Corona/Lua to assign a variable name to represent a table name ?
As the user clicks on a screen item - I want that items name to represent the name of the table being called.
I have 2 lines:
myName = (seedTable[i].seedType)
This line grabs the seed name from a pre-made table, and returns names like strawberry, orange, etc.
Strawberry, orange etc, are also the names of other pre-made tables.
I then want to use myName to dynamically access different tables depending on the name returned.
i.e. in a line like this…
if (myName[count] == true) then
This never seems to work, I can only seem to manually access each seed table as below…
**if (strawberry[count] == true) then or if (orange[count] == true) then , **etc
Also…
If I have tables within tables , i.e.:
planting = {}
planting.loc1 = {multiple data items}
planting.loc2 = {multiple data items}
planting.loc3 = {multiple data items}
etc…
I have been trying to loop through using a line such as
for i = 1, #planting do
if (planting.loc[i].occupied == false) then
– e.g, seed location unavailable for planting
end
end
but no luck.
Is there a way to use variables or a type of concatenation to achieve the result I’m looking for ?
Any help would be very much appreciated!
Matt.
