-1

i have 2 array classMate and winners, in need to check if winners in classMate, if yes put res[i] = 1

function win(classMates , winners)
    res = {}
    for i=1,#winners do
        for j=1,#classMates do
        print(3)
            if winners[i] == classMates[j] then res[i] = 1 else res[i] = 0 end
            print(res)
        end
    end

end
classMates = {"frank" , "alex" , "soli"}
winners = {"lora" , "frank" , "sandra" ,"alex"}
print(winners(classMates,winners))

but when i do that there is an error that said : i use REPL for lua

lua: [string "<eval>"]:15: attempt to call global 'winners' (a table value)

stack traceback: [string ""]:15: in main chunk

any help ?

Blockquote

Nicholas
  • 39
  • 6

1 Answers1

1

do

-- not print(winners)
-- cause winners is a table
-- instead
win({"frank" , "alex" , "soli"}, {"lora" , "frank" , "sandra" ,"alex"})
-- because win() does the print()
-- ...as i can see

end

And also try in win() print(res[i]) the foregoing print(3) should be print(classMates[j])

koyaanisqatsi
  • 2,585
  • 2
  • 8
  • 15