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

Error help

Discussion in 'Development' started by Kyd, May 19, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Im trying to check if player is in array
    Main class:
    PHP:
    /**
    * @param Player $p
    * @return Game
    */
    public function getPlayerArena(Player $p){
        foreach(
    $this->arenas as $arena){
            if(
    $arena->inArena($p)){
                return 
    $arena;
            }
        }
        return 
    false;
    }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args)
    {
        if (
    $sender instanceof Player){
            
    $arena $this->getPlayerArena($sender);
        switch (
    $cmd->getName()) {
            case 
    'vote':
                if (
    $arena === false) {
                    break;
                }
                if (isset(
    $args[1]) || !isset($args[0])) {
                    
    $sender->sendMessage($this->getPrefix() . TextFormat::GRAY "use /vote [map]");
                    break;
                }
                
    $arena->votingManager->onVote($senderstrtolower($args[0]));
                break;
        }
    }
    }
    inArena function in my Game.php
    PHP:
    /** var Player[] $players */
    public $players = [];

    public function 
    inArena(Player $p){
       if(isset(
    $this->players[strtolower($p->getName())])){
           return 
    true;
       }else{
           return 
    false;
       }
    }
    After I use /vote I get this error
    Code:
    [19:06:40] |CRITICAL| Unhandled exception executing command 'vote Canyon' in vote: Call to a member function inArena() on array
    [19:06:40] |CRITICAL| Error: "Call to a member function inArena() on array" (EXCEPTION) in "/plugins/Annihilation/src/Annihilation/Annihilation" at line 102
     
  2. [deleted]

    [deleted] Guest

    Use in_array() to check if something is in a array.
     
  3. SkySeven

    SkySeven Baby Zombie

    Messages:
    145
    GitHub:
    SkySevenMC
    i think in inArena() , $p is an array, not a string
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What is $this->arenas? The error implies that when you call $arena->inArena(), $arena is actually an array, not an object.
    1) None of that is true. $p is a Player object.
    2) Nothing implies that $p is a string.
    3) That's not causing the issue.
    From what little information is provided by OP, I gather that he is not checking if something is in an array. He is checking if a value is set for a certain key. isset() works just fine in this case.
     
    jasonwynn10 and [deleted] like this.
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    $this->arenas is game.php
    PHP:
    /** @ var Game $arenas */
      
    public $arenas = [];
     
    Last edited: May 20, 2017
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I solved I used bad array this must be moved to dev faceplam :D :facepalm: :facepalm: :facepalm: :facepalm: :facepalm:
     
    jasonwynn10 likes this.
  7. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    send code
     
    CV71-codes likes this.
  8. mmm545

    mmm545 Baby Zombie

    Messages:
    152
    GitHub:
    mmm545
    why are you bumping old threads and posting comments on ppl profiles to help you with ores?
     
    Primus likes this.
  9. CV71-codes

    CV71-codes Creeper

    Messages:
    3
    GitHub:
    craveyou-newcoder
    Is
    Is this plugin GigufSecretMaster from ondraczsk ?
    This is old api this won't work for new api
     
  10. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Stop bumping this thread, please. The OP has already solved this issue, and if you want to ask a question, make a new thread
     
    mmm545 likes this.
  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.