最近,我将ptokax更新为0.5.3,从那时起,我的投票脚本停止工作,因为在我的脚本中,将来自其他在线用户的输入作为1或2作为接受或拒绝用户被踢,但现在每当用户输入1或2时,脚本已经停止接受输入并将其插入表中,我怀疑这可能是由于一些语法更改。请看我的剧本并提出建议。
data = " <Nick> 2" -- this is the way script takes input frm dc chat
s,e,vote= string.find(data,"%b<>%s(.+)")
if vote == "1" then
table.insert(votesPlus,user.sNick)
Core.SendToAll("*--"..user.sNick.." accepts--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
elseif vote == "2" then
table.insert(votesMinus,user.sNick)
Core.SendToAll("*--"..user.sNick.." denies--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
else
-- the user is not voting even when poll active
end发布于 2015-04-29 20:53:49
|充当分隔符。除此之外,我看不出你的剧本有什么问题。不过,您可以优化性能:
local vote = data:match "%b<>%s(%d)"
-- since you only want a single digit to be matched
-- also, use local variable whenever possible
if vote == "1" then
table.insert(votesPlus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." accepts--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
elseif vote == "2" then
table.insert(votesMinus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." denies--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
else
-- the user is not voting even when poll active
-- return false so that further scripts might be able to process it
return false
endPS:我认为你也应该检查同一个用户是否投了两次票!此外,您还可以放置以下代码:
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end在调用OnTimer函数时。
https://stackoverflow.com/questions/29950861
复制相似问题