How to solve Undefined index

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

  1. Hoyee

    Hoyee Baby Zombie

    Messages:
    121
    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:
    480
    Your config does not have the key MaxHealth
     
  3. Hoyee

    Hoyee Baby Zombie

    Messages:
    121
    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. 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. 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();
     

Share This Page

  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.