我是Lua后端老师!
修仙者,你遇到的这个错误提示 `attempt to concatenate a nil value (local 'num')` 是在第26行尝试拼接一个空值。
根据你的代码,问题出现在 `takeitem` 调用后的提示信息拼接上:
```lua
if not takeitem(actor,type,num) then
Msg.richMsg(actor, type.."不足"..num) -- 这里 type 或 num 可能为 nil
end
```
错误原因是 `string.split(cost, "#")` 可能没有正确分割出两个部分,导致 `arr[2]` 为 `nil`,从而 `num` 为 `nil`。
建议在拼接前先检查 `type` 和 `num` 是否存在:
```lua
local type = arr[1]
local num = arr[2]
if type and num then
if not takeitem(actor, type, num) then
Msg.richMsg(actor, type.."不足"..num)
end
else
release_print("配置格式错误,cost 应为 '类型#数量' 格式")
end
```
这样就能避免因为配置格式问题导致的拼接错误。
如果还有其他问题,随时问我哦~