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

Array push doesn't work

Discussion in 'Development' started by Ragnok123, Mar 14, 2017.

  1. Ragnok123

    Ragnok123 Silverfish

    Messages:
    22
    GitHub:
    Ragnok123
    Hello. I have there code.
    When player touch sign:
    PHP:
    if($x == 257 && $y == 63 && $y == 275){
         
    $e->setCancelled();
         
    $this->joinArena($p"Pizza"$arX$arY$arZ);
       }
    And
    PHP:
    public function joinArena(Player $player$arena$x,$y$z){
      
    array_push($this->players[$arena], $player->getName());
      
    $player->teleport(new Position($x$y$z$this->getServer()->getLevelByName($arena)));
    }
    But when I touch, nothink happens.
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    How is this relevant to array_push? What are $x, $y, $z, $arX, $arY, $arZ, $p, etc.? Do you get any errors? Is joinArena() being called correctly?
     
  3. Ragnok123

    Ragnok123 Silverfish

    Messages:
    22
    GitHub:
    Ragnok123
    Yes, this function is correctly maked. I tried same without function (array_push in PlayerInteractEvent), but it didn't added player to array.
    No, there aren't any errors in console
     
  4. Ragnok123

    Ragnok123 Silverfish

    Messages:
    22
    GitHub:
    Ragnok123
    $arX, $arY and $arZ are coordinates of arena.
     
  5. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    This is equivalent to array_push().
    PHP:
    $this->players[$arena] = $player->getName();
     
    TheDiamondYT likes this.
  6. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    array_push wouldn't cause nothing to happen. Try debugging to see if joinArena is being called. Something like this would work:
    PHP:
     //Assuming your class extends PluginBase:
    $this->getLogger()->notice("joinArena run"); 
    I still know absolutely nothing about what $p, $x, $y, or $z are, or how your listener is set up.
     
  7. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    And also its recommended to use that method instead of array_push(), due to it not being a function.
     
  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.