문제

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