1

I am trying to edit a script in LUA but I couldn't get access of a local defined in a function

LUA Code

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())

Result : nil

here's the sql function as sysdevs asked

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
2
  • could you provide QBCore.Functions.ExecuteSql ? Commented Dec 23, 2020 at 0:09
  • @sysdevs updated Commented Dec 23, 2020 at 0:11

1 Answer 1

1

Your second function is not holding the main function I assume, I am bad at lua aswell, but I think that changing

QBCore.Functions.ExecuteSql(false, ............

to

QBCore.Functions.ExecuteSql(true, ............

This will probably fix your problem, still your code is ambiguous and needs concentration if you could provide more information I might be able to help more

Sign up to request clarification or add additional context in comments.

1 Comment

it is a game script code, taking some time to execute, will provide you with news. Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.