1

I am having a few issues with tables and calling some values from them. Here is what I mean:

cartable = {"Car1", "Car2"}

table = "cartable"

for i = 1, #table do
print(table[i])
end

This is a very simplified version of my issue, but that is basically it. How can I use a string (must be using a string) to set a variable as a table?

1 Answer 1

1

If it's a global variable like in your example, you can use _G[table] to access the variable with the name of that string.

for i = 1, #(_G[table]) do
     print(_G[table][i])
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.