首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在lua中为ptokax脚本添加变量值

在lua中为ptokax脚本添加变量值
EN

Stack Overflow用户
提问于 2015-04-29 17:44:45
回答 1查看 289关注 0票数 1

最近,我将ptokax更新为0.5.3,从那时起,我的投票脚本停止工作,因为在我的脚本中,将来自其他在线用户的输入作为1或2作为接受或拒绝用户被踢,但现在每当用户输入1或2时,脚本已经停止接受输入并将其插入表中,我怀疑这可能是由于一些语法更改。请看我的剧本并提出建议。

代码语言:javascript
复制
   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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-29 20:53:49

  1. 请说明您是使用发布的PtokaX与Lua5.3.0还是5.1.5一起使用。
  2. NMDC中心协议定义聊天消息以下列格式发送: 消息\x 其中|充当分隔符。

除此之外,我看不出你的剧本有什么问题。不过,您可以优化性能:

代码语言:javascript
复制
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
end

PS:我认为你也应该检查同一个用户是否投了两次票!此外,您还可以放置以下代码:

代码语言:javascript
复制
if #votesPlus == votes or #votesMinus == votes then
    stop( nTimerId )
end

在调用OnTimer函数时。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29950861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档