LUA | MTA尝试索引全局“ zoneName”(nil值)

问题描述 投票:0回答:1

[我正在学习的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
lua lua-table
1个回答
0
投票

您已经在定义中引用zoneName,您的代码等于

local zoneName = nil:gsub(“'”,“”)

因此,错误(Lua尝试执行zoneName:gsub()时尚未定义zoneName。

要么在gsub()调用之前定义zoneName,要么使用string.gsub()

© www.soinside.com 2019 - 2024. All rights reserved.