Reputation: 131
I have this function:
wins = {}
players={}
function Wins(name)
for i,wins in ipairs(wins) do
if name==wins then
return true
end
end
return false
end
function eventNewGame()
for name in pairs(tfm.get.room.playerList) do
counter[name] = 0
counterTotal[name] = counterTotal[name]
table.insert(wins, name)
end
if Wins(name) then
players[name]={wins=0}
print('okay')
end
However, it doesn't work. (It doesn't print 'okay' and does not set players[name]={wins=0}) What am I doing wrong?
Thanks in advance!
Upvotes: 0
Views: 67
Reputation: 1
It seems to be you're not ending or calling your function in the code you're shown. You don't end your for loop in the function eventNewGame() and you never declared name, causing it to be nil. Another thing may be in
if name==wins then
you're comparing to a table value and not a value from the table. So first you need to declare name then you need to explicitly state what it's comparing to such as
if name == wins.var then
or
if name == wins[1] then
or
if name == wins[var] then
Hopefully this makes sense and helps.
Upvotes: 0
Reputation: 72312
name
is nil in the line below, unless there is a global variable name
:
if Wins(name) then
Upvotes: 1