1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Fetching data from a database

Discussion in 'Development' started by Levi, Feb 19, 2019.

  1. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you should unset the player from the array when they leave to save some memory incase they don't come back, when the server stops, you should save everything on the array to your MySQL and do DataConnector->waitAll() so you make sure it saves
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Is there a way to make sure that the data from mysql get stored to an array on PlayerJoinEvent?
     
  3. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    DataConnector::waitAll()
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Sofe said to only use it on events like onDisable()
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Don't use waitAll in PlayerJoinEvent. That entirely defeats the point of making things async.
     
    Muqsit likes this.
  6. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    do you have any other ideas?
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  8. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    trying to find a way to make sure that the data from mysql get stored to an array on PlayerJoinEvent
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You can't. You have to accept the fact that the array may not be initialized yet. Therefore, don't do anything until the libasynql success callback is invoked.
     
  10. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    thanks for telling, and as you said the other solution defeats the purpose of making things async
     
  11. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I use waitAll() on something else in onDisable()
    Is it guaranteed that all data
    How do I do know I'm not doing anything until libasynql success callback is invoked
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    waitAll() basically means "stop the world and do nothing waiting for the reply", which is doing the exact same thing as synchronous query. And you should not do that unless the server is starting/stopping.
    Just check if the data are set before accessing it? That really depends on your case.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.