Function returns

Hi All,

Having some trouble understanding how to get functions to return data…

function getZones()
        MySQL.Async.fetchAll('SELECT * FROM zones', {}, function(data)
                print('MySQL Data: '..type(data))
                return data
        end)
end

Citizen.CreateThread(function()
        zones = {}
        zones = getZones()
        Citizen.Wait(2000)
        print('Zones: '..type(zones))
end)

The following outputs:

MySQL Data: table
Zones: nil

Can anybody point out what I’m doing wrong? Cheers!

The function already returns before the callback has finished

how do I wait until the callback is finished? Do I have to wrap the function in a registered server event?

Use MySQL.Sync or add an callback parameter to your getZones() function

Cheers, adding a callback worked

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.