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

Why only one user written

Discussion in 'Development' started by Hoyee, Aug 7, 2020.

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    PHP:
    foreach ($this->getServer()->getOnlinePlayers() as $O){

        
    $this->DA["GAM"][] = $O->getName();
    and when I see the file of plugin data, it has only one people.

    like

    ---
    GAM : Steve
    ...
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    I might guess, that you're not correctly loading the saved data, so in other words, you are re-writing the data not appending to it.

    Could you please show the code which is responsible for loading and saving the data.
    Also please try using hard coded values like this:

    PHP:
    foreach(["Steve""Alex""Notch""Shoghicp"] as $player) {
       
    $this->data["someKey"][] = $player;
    }
    P.S. stop naming the variables so vague. Code is meant for people to read, you're making hard on yourself and others.
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    okay, and this was my code
    Code:
    foreach ($this->getServer()->getOnlinePlayers() as $O){
    
        $this->DA["GAM"][] = $O->getName();
    
        $this->DADA->setAll($this->DA);
        $this->DADA->save();
    
    }
     
  4. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    But don't you have to write down the name of the player in advance to use the code you said?
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    // will append to current loaded data.
    $this->DADA->setAll(array_merge($this->DATA->getAll(), $this->DA));
     
  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.