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

Undefined offset: 1 (Nesting fail?)

Comments in 'Plugin Development' started by Andrey Nazarchuk, Nov 6, 2015.

  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello Again Everyone!!!
    After coding for a while then not coding for a while, I stumbled upon this error:
    Code:
    [Server thread/CRITICAL]: Unhandled exception executing command 'play' in play: Undefined offset: 1
    [20:22:38] [Server thread/NOTICE]: ArrayOutOfBoundsException: "Undefined offset: 1" (E_NOTICE) in "/SkyWars/src/SkyWars/SkyWars" at line 413
    
    Here's the code:
    PHP:
                    $this->nextSpawn($get 0$set 1);
         
    Line [408$this->cords[] = $this->worlds->getNested($this->arena.$this->nextSpawnNumber);
                    
    $this->getLogger()->info($this->cords[0]);
                    
    var_dump($this->cords[0]);
                    
    $this->world $this->getServer()->getLevelByName($this->arena);
                    if(
    $this->cords[0] == NULL or $this->cords[1] == NULL or $this->cords[2] == NULL or $this->nextSpawnNumber $this->maxSlots or $this->world == null){
             
    Line [413$player->sendMessage($this->swm->get('prefix') . $this->swm->get("oops") ."SK407: ".$this->cords[0].$this->cords[1].$this->cords[2]);
                        return;
                    }

    I am positive there is something wrong with line 408 and its making line 413 sad :( .
    var_dump's for $this->cords[0]; return NULL.

    Here is the worlds config file as set up in the code:
    PHP:
    $this->worlds = new Config($this->getDataFolder()."worlds.yml"Config::YAML, array(
                
    "JungleRuins" => [
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    10 => [
                    
    128,
                    
    5,
                    
    128
                  
    ],
                  
    11 => [
                    
    128,
                    
    5,
                    
    128
                  
    ]
                ]
            ));

    Thanks for Reading!!!
  2. Svile
    Offline

    Svile Active Member

    Joined:
    Mar 30, 2015
    Posts:
    239
    Minecraft User:
    svile
    $cords[1] doesn't exist
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Yes but why?
  4. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Pretty basic mistake:
    Line 408 must be
    PHP:
    $this->cords[] = $this->worlds->getNested($this->arena.".".$this->nextSpawnNumber);
    You hat the dot for string connection, but not the one for getNested
    Andrey Nazarchuk likes this.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I disagree.
    $cords[0]*
    do
    PHP:
    var_dump($var/*[0]*/); // without key selector
    Andrey Nazarchuk likes this.
  6. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Thanks!
    But:
    PHP:
    $this->cords[] = $this->worlds->getNested("$this->arena.$this->nextSpawnNumber");
    Returns the same result, and is equal to what you wrote.
    thebigsmileXD likes this.
  7. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Says array to string conversion exception...
  8. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  9. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    It appears that one of the functions inside "getNested()" function is an array.. can you check that?
    Andrey Nazarchuk likes this.
  10. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Arena is a string and the other is an int.
  11. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Then the "getNested" function is returning an array... :/
    Andrey Nazarchuk likes this.
  12. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    That's what I want it to return, it is supposed to hold coordinates.
  13. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Got it, try with:
    PHP:
    $this->code = ...
    Note the missing "[]" after the "$this->code" variable
    Andrey Nazarchuk likes this.
  14. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Still undefined offset.
  15. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    So you understand how "arrays" work in PHP? You can not "say they're arrays"... You need to make some array-variable movements in order to express the contents of the array as a string
    Andrey Nazarchuk likes this.
  16. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    To use "nested" function use:
    PHP:
    getNested($this->arena "." $this->nextSpawnNumber);
    Andrey Nazarchuk likes this.
  17. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Exactly what I did, it works now. Thanks!

Share This Page

Advertisement