Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Undefined index

Comments in 'Plugin Development' started by luca28pet, Sep 8, 2014.

Thread Status:
Not open for further replies.
  1. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Hi all, ...
    So, I'm becoming mad with configs (again): here is my code:
    PHP:
    $a $this->config->get('areas');
    $an array_shift($args);
    array_push($a$an);
    $this->config->set($a[$an], array(/*Random data...*/); //this is line 93
    I get an E_NOTICE error: "Undefined index: name*" at line 93
    *the word 'name' changes depending on the command parameter I type.
    Can anybody help me please?
    Thanks in advice.
    Last edited: Sep 8, 2014
    EkiFoX likes this.
  2. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    PHP:
    $a $this->config->get('areas');
    $an array_shift($args);
    array_push($a$an);
    $this->config->set($a[$an], array(/*Random data...*/); //this is line 93
  3. EkiFoX
    Offline

    EkiFoX Active Member Plugin Developer

    Joined:
    Feb 28, 2014
    Posts:
    95
    Plugins:
    2
    Minecraft User:
    ekifox
    LDX likes this.
  4. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    I get still the same error..
  5. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    That's the only thing I changed. :p
  6. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    Does anyone else have other possible solutions?
  7. LDX
    Offline

    LDX Notable Member Plugin Developer

    Joined:
    Oct 2, 2013
    Posts:
    1,434
    Plugins:
    14
    Try this:
    PHP:
    $a $this->config->get('areas');
    $an array_shift($args);
    $this->config->set($a[count($a)],$an); // This is line 92
  8. luca28pet
    Offline

    luca28pet Active Member

    Joined:
    Feb 20, 2014
    Posts:
    251
    Minecraft User:
    luca28pet
    No :( error: Undefined offset: 1
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    array_push() adds an element to the end of an array, and the key should be the size of array.
    Use this:
    PHP:
    $a $this->config->get("areas");
    $an array_shift($args);
    $a[$an] = $someData;
    $this->config->set("areas"$a);
    And again, you are discouraged to use $this->config directly. Try renaming $this->config to $this->cfg.
    luca28pet and Falk like this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement