lua - Lua:返回表槽函数为零
问题描述
我收到错误:source_file.lua:5: 尝试调用 nil 值(全局“getCard”)
我尝试在 questCards 中找到正确的表,其中 Index=name 与 objName 中的给定字符串相同
questCards={{['name']='test1',['creatureName']='test3'},{['name']='test2',['creatureName']='test4'}}
obj='test1'
card=getCard(obj)
card['creatureName']=nil --Only for test purpose
if card['creatureName']==nil then
--do Somthing
end
function getCard(objName)
for k,v in pairs(questCards) do
if v['name']==objName then
return v
end
end
end
解决方案
错误消息告诉您getCard
在调用它时未定义。
您需要getCard
在调用它之前进行定义。
推荐阅读
- c++ - SystemC sc_signal 数组内存边界
- c# - 在自定义验证器中设置不区分大小写
- asp.net - Serenity Framework 日期时间显示在列和表单上
- http - Ionic 3 - Http 获取 401(未经授权)
- python - 如何更改 x 轴以在 matplotlib 内联上显示“状态”
- javascript - 所有 »scrollable« 元素的全局滚动监听器
- android - 显示通知时播放两次通知声音
- java - 在超级账本结构中使用 JAVA Sdk 手动背书交易
- powershell - 通过 Powershell 使用自定义安装路径和组件静默安装 Visual Studio 的参数
- linux - 如何在linux下使用mosix集群包运行cpuminer-multi挖矿包