使用外部函数变量的LUA
我试图在LUA中编辑脚本,但无法访问函数中定义的本地脚本 LUA代码使用外部函数变量的LUA,lua,Lua,我试图在LUA中编辑脚本,但无法访问函数中定义的本地脚本 LUA代码 function getSafeMoney() local SafeMoney = nil QBCore.Functions.ExecuteSql(false, 'SELECT * FROM `moneysafes` WHERE `safe` = "mechanic"', function(result) SafeMoney = json.decode(json.e
function getSafeMoney()
local SafeMoney = nil
QBCore.Functions.ExecuteSql(false, 'SELECT * FROM `moneysafes` WHERE `safe` = "mechanic"', function(result)
SafeMoney = json.decode(json.encode(result[1])).money;
end)
return SafeMoney
end
print(getSafeMoney())
结果:
零
下面是sysdevs要求的sql函数
QBCore.Functions.ExecuteSql = function(wait, query, cb)
local rtndata = {}
local waiting = true
exports['ghmattimysql']:execute(query, {}, function(data)
if cb ~= nil and wait == false then
cb(data)
end
rtndata = data
waiting = false
end)
if wait then
while waiting do
Citizen.Wait(5)
end
if cb ~= nil and wait == true then
cb(rtndata)
end
end
return rtndata
end
你的第二个函数不是我假设的主要函数,我也不擅长lua,但我认为这是在改变
QBCore.Functions.ExecuteSql(false, ............
到
这可能会解决您的问题,但您的代码不明确,需要集中精力如果您能提供更多信息,我可能会提供更多帮助您能提供QBCore.Functions.ExecuteSql吗?@sysdevs updateedit是一个游戏脚本代码,需要一些时间来执行,将为您提供新闻。谢谢你的帮助。干得好,做得很好
QBCore.Functions.ExecuteSql(true, ............