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

Solved getOnlinePlayers undef offset

Comments in 'Plugin Development' started by MinePocket Servers, Apr 24, 2016.

  1. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    PHP:
    $pc count($this->getServer()->getOnlinePlayers());
    $arr $this->getServer()->getOnlinePlayers();
    //while loop
        
    $pc--;
        
    $play $arr[$pc];
        
    $name $arr[$pc]->getName();
    Problem: Undefined offset (Numofplayers - 1), call to member function getName()

    I've done a var dump and $arr does contain $pc online and does contain player object
  2. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    Oh this is an async task calling this function.
  3. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    Notice: Undefined offset: 0 in C:\Users\Jamie\Desktop\PocketMine-MP\plugins\MPFacPLUG\src\MPFac\MPFac.php on line 505
    [11:31:42] [Server thread/CRITICAL]: Could not execute task MPFac\Timer: Call to a member function getName() on null
    [11:31:42] [Server thread/CRITICAL]: Error: "Call to a member function getName() on null" (EXCEPTION) in "/MPFacPLUG/src/MPFac/MPFac" at line 506
  4. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    If it is in another class you can try instead of $this-> $this->getOwner ()
  5. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    That just crashes it onload

Share This Page

Advertisement