我有这个脚本
players={}
function eventNewGame()
local playerList={}
for name,tbl in pairs(players) do
if tbl.wins>most.wins then
most={name=name,wins=tbl.wins}
end
table.insert(log.cheese, "<j><b>"..most.name.."</b> <vp>won the round for gathering <ROSE><b>"..most.wins.." cheese!</b><N>")
end
然而,它打印/发送/插入的次数与房间中的人数相同。我怎么能这样做它只插入一次?
答案 0 :(得分:3)
您错过了end
循环的结束for
,这导致insert
行位于循环内。你需要添加它:
for name,tbl in pairs(players) do
if tbl.wins>most.wins then
most={name=name,wins=tbl.wins}
end
end -- <---- add this
table.insert(log.cheese, "<j><b>"..most.name.."</b> <vp>won the round for gathering <ROSE><b>"..most.wins.." cheese!</b><N>")
最后你可能还有一个额外的end
(否则你的代码无法编译),你需要删除它。