2012-04-22 112 views
-1

我正在使用C++和Lua進行MUD,我正在嘗試爲emotes創建一組函數。添加Lua函數語法

我已經寫了:

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連接到服務器,我可以鍵入:

說 「HI」 - >所有的人都期望看到喜。

我可以輸入:

說 「嗨」 playerBob - > playerBob看到喜就好

但是,如果我簡單地鍵入:dance 我得到一個錯誤信息當它無法識別任何動詞時發送。 我假設add_atoms{ dance = 'verb' }固定的,但...

有沒有人碰巧知道爲什麼我無法跳舞發生?

回答

0

[解決]

「add_atoms {舞蹈= '動詞'}」 中不add_functions代碼去。 它必須在add_functions方法之外完成,或者至少可以做到。 像這樣:

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

add_functions 
{ 
... 
} 
+0

如果你已經知道了你的問題,你可以將自己的答案標記爲正確答案。 – Kyle 2012-04-22 20:36:26

+0

是的。 這讓我等到明天才會接受我的評價。但我想。 – 2012-04-23 04:27:13