質問

local questions={
    EN={
        Q1={"",""},
        Q2={"",""},
        Q3={"",""},
        Q4={"",""},
        Q5={"",""},
        Q6={"",""},
        Q7={"",""},
        Q8={"",""},
        Q9={"",""},
        Q10={"",""}
    },
    BR={
        Q1={"",""},
        Q2={"",""},
        Q3={"",""},
        Q4={"",""},
        Q5={"",""},
        Q6={"",""},
        Q7={"",""},
        Q8={"",""},
        Q9={"",""},
        Q10={"",""}
    },
    TR={
        Q1={"",""},
        Q2={"",""},
        Q3={"",""},
        Q4={"",""},
        Q5={"",""},
        Q6={"",""},
        Q7={"",""},
        Q8={"",""},
        Q9={"",""},
        Q10={"",""}
    }
}
local current_question = questions.EN.Q..math.random(1,10)[1]

I want to make the current_question variable return a random question from the questions table but it gives me an error; "attempt to index ? (a number value)"

役に立ちましたか?

解決

You need to tell the interpreter Q..math.random(1,10) is one string like this:

local current_question = questions.EN["Q"..math.random(1,10)][1]
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top