0

Is it possible to use a variable in an object reference in Lua? For example, a.Value is a string, and a.Value = "b". I would like to access a.b.c.d, or a.(a.Value).c.d. How can I accomplish this?

1 Answer 1

3

The syntax a.b is actually shorthand for a["b"]. To do what you want, you'd get rid of the "b" and instead use the variable, like this:

a[a.Value].c.d
Sign up to request clarification or add additional context in comments.

1 Comment

Interesting! So objects can be treated like arrays (if I'm not confusing my array syntax)? Seems to work! Thank you!

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.