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

command arg isn't working?

Discussion in 'Facepalm' started by Teamblocket, Jul 8, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    i have this onCommand function but when i do /price <player> it just returns the sender price
    PHP:
        public function onCommand(CommandSender $senderCommand $cmd$label, array $param){
            if(
    strtolower($cmd->getName()) === "price"){
                if(isset(
    $args[0])){
                    
    $target $this->getServer()->getPlayer($args[0]);
                    if(
    $target !== null && $target->isOnline()){
                        
    $sender->sendMessage("§l§c  TheVortex §7>> §r§e ".$target->getName()." §7 is worth §l§a$ §r§f§a".$this->getWorth($target));
                    } else {
                        
    $sender->sendMessage("§l§c  TheVortex §7>> §r§4 ".$target->getName()." Isnt online!");
                    }
                } else {
                    
    $sender->sendMessage("§l§c  TheVortex §7>> §r§§§7Your head is worth §l§a$ §r§f§a".$this->getWorth($sender));
                }
            }
        }
    }
     
  2. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    huh u made array $param not $args
     
  3. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    PHP:
     public function onCommand(CommandSender $senderCommand $cmd$label, array $param){
            if(
    strtolower($cmd->getName()) === "price"){
                if(isset(
    $param[0])){
                    
    $target $this->getServer()->getPlayer($param[0]);
                    if(
    $target !== null && $target->isOnline()){
                        
    $sender->sendMessage("§l§c  TheVortex §7>> §r§e ".$target->getName()." §7 is worth §l§a$ §r§f§a".$this->getWorth($target));
                    } else {
                        
    $sender->sendMessage("§l§c  TheVortex §7>> §r§4 ".$target->getName()." Isnt online!");
                    }
                } else {
                    
    $sender->sendMessage("§l§c  TheVortex §7>> §r§§§7Your head is worth §l§a$ §r§f§a".$this->getWorth($sender));
                }
            }
        }
     
    Teamblocket likes this.
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    !! thanks
     
    VCraft likes this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    PHP does not report undefined variables when they are used in the array syntax...
     
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    nope it doesn't , but i did get a error when running the command , an error on explode() function even tho i never used it
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Set debug.level to 2 and look at the trace. You'll hopefully see which line in your code leads to the bug.
     
  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.