brouznouf / fivem-mysql-async

MySql Async Library for FiveM
MIT License
111 stars 106 forks source link

How to get data out of the callback? #116

Closed TheRealCrappyGamer closed 4 years ago

TheRealCrappyGamer commented 4 years ago

When trying to use a MySql.Async.fetchAll(), inside of the callback, I cannot seem to get variables to be set and accessible outside of the callback.

I have access to a variable outside of the callback, but once I change it in the callback, it's not updated outside of it. Is there a way to pass the variable in so that I can manipulate it and get it back out?

TimBunk commented 4 years ago

I am having the same issue at the moment and I also can't trigger client events within the callback.

djmetla commented 4 years ago

Any solution for this? Currently this lib is unusable

Rubylium commented 4 years ago
MySQL.Async.fetchAll('SELECT * FROM player', {}, function(players)
    print(players[1].name)
end)
TheRealCrappyGamer commented 4 years ago

This doesn't help with storing the value outside of the callback, or updating a variable while inside the callback.

On Thu, Feb 20, 2020, 4:20 AM Rubylium notifications@github.com wrote:

MySQL.Async.fetchAll('SELECT * FROM player', {}, function(players) print(players[1].name) end)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/brouznouf/fivem-mysql-async/issues/116?email_source=notifications&email_token=AAKAVX3ACIHQODKPPT6P333RDZDPPA5CNFSM4KI6R5B2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMMNF6A#issuecomment-588829432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKAVX7ERNBGMH276AKANYDRDZDPPANCNFSM4KI6R5BQ .

TheRealCrappyGamer commented 4 years ago

An example is this:

if checkPlayerExists(identifier) then
  print("The user exists")
end
function checkPlayerExists(identifier)
  MySQL.Async.fetchAll('SELECT * FROM `users` WHERE `identifier` = @identifier',    
   {
      ['@identifier'] = identifier,   
    }, function(result)
      if #result > 0 then
         return true
      end
  end)
end
CaioCartaxo commented 4 years ago

I have the same problem here, even in the bugged IVMP I can work with the returned value and not here ...