Let me explain.
Here I have 2 arrays:
amountOfAnswers = {2, 1}
answers = {"Yes", "No", "Maybe"}
I wanna do something like: If ‘amountOfAnswers’ = 2 then choose the 2 next values of ‘answers’ but I don’t know how to write it.
Let me explain.
Here I have 2 arrays:
amountOfAnswers = {2, 1}
answers = {"Yes", "No", "Maybe"}
I wanna do something like: If ‘amountOfAnswers’ = 2 then choose the 2 next values of ‘answers’ but I don’t know how to write it.
(Repost)
If you want to iterate through amountOfAnswers
and pick that number of answers from the answers
array, you can try something like:
“local amountOfAnswers = {2, 1}
local answers = {“Yes”, “No”, “Maybe”}
local currentIndex = 1
for i = 1, #amountOfAnswers do
local count = amountOfAnswers[i]
local selectedAnswers = {}
for j = 1, count do
table.insert(selectedAnswers, answers[currentIndex])
currentIndex += 1
end
-- Do something with selectedAnswers
print("Selected answers for group " .. i .. ":")
for _, ans in ipairs(selectedAnswers) do
print(ans)
end
end”
This should output
“Selected answers for group 1:
Yes
No
Selected answers for group 2:
Maybe”
Get the amount in amountofanswers, then loop through answers with that amount, and repeat
local amount = amountofanswers[1] —2
local answerst = {}
for i = 1,amount,1 do
table.insert(answerst,answers[i])
end
print(answerst)
I found a way to do it.
local answer
for i = 1, amountOfAnswers[currentline] do
answer = answers[answerIndex]
print(answer)
answerIndex += 1
end
I could have used your types of code but I’m not understanding anything T-T
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.