I have this script

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

However, it prints/sends/inserts as many times as people in the room. How could I make it so it inserts only ONE time?

enter image description here

有帮助吗?

解决方案

You are missing the closing end of the for loop, which causes the insert line to be inside the loop. You need to add it:

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>")

You probably also have an extra end at the end (otherwise your code wouldn't compile), which you will need to remove.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top