【问题标题】:Adding Lua Function Syntax添加 Lua 函数语法
【发布时间】:2012-05-03 06:01:54
【问题描述】:

我正在使用 C++ 和 Lua 开发一个 MUD,并且我正在尝试为表情创建一组函数。

我写过:

add_functions
{
   ['subject-bind-search say'] = 'none',
   ['player say string-type'] = function(player, msg)
      player_text(player, 'You say "' .. msg.string .. '".')
      witness_text(player, M('indefinite', player) .. ' says "' .. msg.string .. '".')
   end,
   ['subject-bind-search say-to'] = 'none',
   ['player say-to string-type thing'] = function(player, msg, thing)
      player_text(player, 'You say "' .. msg.string .. '" to ' .. M('definite',thing) .. '.')
      witness_text(player, M('indefinite', player) .. ' says "' .. msg.string .. '" to ' .. M('indefinite', thing) .. '.')
      end,
      ['player dance'] = function(player)
        player_text(player, 'You burst into dance.')
        witness_text(player, M('indefinite', player)..' bursts into dance.')
        add_atoms{dance='verb'}
        end 
}

当我和其他人通过 telnet 连接到服务器时,我可以输入:

say "hi" --> 每个人都可以随心所欲地看到 hi。

我可以打字:

对 playerBob 说“嗨” --> playerBob 看到你好

但是,如果我简单地输入:dance 当它无法识别任何动词时,我收到一条错误消息。 我以为add_atoms{ dance = 'verb' } 修复了这个问题,但是……

有谁知道为什么我不能跳舞?

【问题讨论】:

    标签: scripting syntax lua


    【解决方案1】:

    [已解决]

    "add_atoms { dance = 'verb' }" 不在 add_functions 代码中。 它必须或至少可以在 add_functions 方法之外进行。 像这样:

    add_atoms{[{'say', 'dance', 'apologize', 'bark', 'flex'}]='verb', to='preposition'}
    
    add_functions
    {
    ...
    }
    

    【讨论】:

    • 如果您已经找出问题所在,您可以将自己的答案标记为正确答案。
    • 是的。它让我等到明天才会接受我将其标记为正确。但我愿意。
    猜你喜欢
    • 2018-12-08
    • 2018-09-17
    • 2014-01-31
    • 2017-05-21
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    相关资源
    最近更新 更多