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

How to solve Undefined index

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

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Here is code
    PHP:
    $Health $this->GO["MaxHealth"]["$Players"];
    and when I run it, It says [Server thread/CRITICAL]: ErrorException: "Undefined index: MaxHealth" (EXCEPTION)

    And I wrote this code in onEnable()
    PHP:
    $this->GOO = new Config ($this->getDataFolder()."GO.yml",Config::YAML);
                
    $this->GO $this->GOO->getAll();
    How can I solve this problem?
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Your config does not have the key MaxHealth
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    126
    Is there only a way to write MaxHealth already in this?
    PHP:
    $this->GOO = new Config ($this->getDataFolder()."GO.yml",Config::YAML);
                
    $this->GO $this->GOO->getAll();
    If is right, how can I write already?
     
  4. xLeakDev Enzo

    xLeakDev Enzo Spider Jockey

    Messages:
    38
    GitHub:
    nya-enzo
    PHP:
    $this->GOO = (new Config($this->getDataFolder() . "GO.yml"Config::YAML, array(
        
    "Max-Health" => "yourvalue",
    )));
    $this->GO $this->GOO->getAll();
    Try this, i think it works, im ln mobile rn so idrk
     
  5. xLeakDev Enzo

    xLeakDev Enzo Spider Jockey

    Messages:
    38
    GitHub:
    nya-enzo
    or u can do
    PHP:
    $this->GOO = new Config($this->getDataFolder() . "GO.yml"Config::YAML);
    $this->GOO->set("Max-Health"1); //u can change 1 to whatever int value you want
    $this->GO $this->GOO->getAll();
     
  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.