道友你好,我是lua后端老师!
小仙,这个问题是因为你的函数调用方式不对。在QF触发中,当通过按钮的`link`参数调用函数时,引擎会把所有参数合并成一个字符串,作为第一个参数传递给函数。
看你的代码:
```lua
<Button|ay=1|x=72.0|y=258|color=255|size=18|nimg=xixi/yidalu/hunposhizhe/2.png|link=@shenghun,]]..givehun..[[,]]..takehun..[[,]]..hunmoneyid..[[,]]..hunmoneynum..[[,]]..huncailiao..[[,]]..hunnum..[[>
```
这里`link`参数包含了多个值,但引擎会把`@shenghun,]]..givehun..[[,]]..takehun..[[,]]..hunmoneyid..[[,]]..hunmoneynum..[[,]]..huncailiao..[[,]]..hunnum..[[`这个完整字符串作为第一个参数传给`shenghun`函数。
正确的做法是:在函数内部解析这个字符串。修改你的函数如下:
```lua
function shenghun(actor, params)
-- 解析参数字符串
local paramList = {}
for param in string.gmatch(params, "([^,]+)") do
table.insert(paramList, param)
end
-- 现在paramList[1]是givehun, paramList[2]是takehun, 以此类推
local give = paramList[1] or ""
local take = paramList[2] or ""
local huobi = tonumber(paramList[3]) or 0
local money = tonumber(paramList[4]) or 0
local cailiao = paramList[5] or ""
local num = tonumber(paramList[6]) or 0
release_print("玩家:" .. actor)
release_print("给予物品:" .. give)
release_print("收取物品:" .. take)
release_print("货币ID:" .. tostring(huobi))
release_print("货币数量:" .. tostring(money))
release_print("材料:" .. cailiao)
release_print("材料数量:" .. tostring(num))
end
```
这样就能正确解析所有参数了。记住,在QF中通过`link`调用函数时,所有参数会合并成一个字符串传递,需要在函数内部进行拆分解析。
明白了吗?如果还有其他问题,随时问我!