質問

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