[我正在学习的Lua脚本中遇到问题(我是Lua的新手),这个错误使我非常困惑,当我运行代码时,它给了我以下错误:
attempt to index global "zoneName" (a nil value)
这是我的代码:
local zoneName = zoneName:gsub ( "'", "" )
if dbExec ( handler, "INSERT INTO `safeZones` (`rowID`, `zoneName`, `zoneX`, `zoneY`, `zoneWidth`, `zoneHeight`) VALUES (NULL, '".. tostring ( zoneName ) .."', '".. tostring ( zoneX ) .."', '".. tostring ( zoneY ) .."', '".. zoneWidth .."', '".. zoneHeight .."');" ) then
createSafeZone ( { [ "zoneName" ] = zoneName, [ "zoneX" ] = zoneX, [ "zoneY" ] = zoneY, [ "zoneWidth" ] = zoneWidth, [ "zoneHeight" ] = zoneHeight } )
outputDebugString ( "Safe Zones: Safe zone created name: ".. tostring ( zoneName ) )
return true
else
return false, "Unable to create the safe zone"
end
您已经在定义中引用zoneName,您的代码等于
local zoneName = nil:gsub(“'”,“”)
因此,错误(Lua尝试执行zoneName:gsub()时尚未定义zoneName。
要么在gsub()调用之前定义zoneName,要么使用string.gsub()