2

I want to do something like the following:

local archetype = "melee"
local meleeNames = { x,y,z }

if itemNumber > # [archetype .. "Names"] then 
    itemNumber = # [archetype .. "Names"] 
end

However, I am not sure how to access the variable and this isn't it...

[archetype .. "Names"] 

Thanks, Gullie

1
  • 3
    You can't make up syntax like that. If the variable is global, use the _G table. But the variable is local in your code, in that case, read Access local variable by name Commented Sep 11, 2014 at 6:59

1 Answer 1

5

As @yu-hao said in his comment, you'can make up a syntax like that. You can use nasty tricks to have a similar effect, but that's not recommended. Instead do something like this:

local archetypes = { meleeNames = { x, y, z },
                     ... others }
local archetype = "melee"

if itemNumber > #archetypes[archetype .. "Names"] then
  itemNumber = #archetypes[archetype .. "Names"]
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.