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

Help, I am confused with this error.

Discussion in 'Development' started by Vaxrp, Sep 20, 2017.

Thread Status:
Not open for further replies.
  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    the error is a syntax error "public" not expected, expected "," or ";" on line 20

    here is the code...

    <?php

    namespace KnockbackM;

    use pocketmine\event\Event;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\Server;
    use pocketmine\Player;
    use pocketmine\PluginBase;
    use pocketmine\event\Listener;


    class Main extends PluginBase implements Listener{

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
    }
    19 - public $knockback = 0.4
    20 - public function onCommand(Command $cmd, CommandSender $sender, array $args, $label) {
    if($cmd->getName() == "kb"{$event->setKnockback($args[0]));
    $sender->sendMessage(c::RED. "Knockback Set!"
    }
    }



    public function onDamage(EntityDamageEvent $event) {
    if($event instanceof EntityDamageByEntityEvent){
    $event->setKnockback();

    }
    }
    }
     
  2. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    no have a ";" in line 19.
     
  3. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Now I have this error on line 22
    "Unexpected ")" on line 22"
    22 - if($cmd->getName() == "kb"{$event->setKnockback($args[0]));


    any idea? Im sure there is no unexpected ")"
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    it's a SYNTAX ERROR!
    read the error!
    this can be resolved by reading every single line and knowledge of PHP syntax OR use a ide
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Here, I fixed your syntax, but please, learn the php syntax:
    PHP:
    <?php
    namespace KnockbackM;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\PluginBase;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{
      public function 
    onEnable() {
        
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
      }

      public 
    $knockback 0.4;

      public function 
    onCommand(Command $cmdCommandSender $sender, array $args$label) {
        if(
    $cmd->getName() == "kb") {
          
    $event->setKnockback($args[0]);
          
    $sender->sendMessage(c::RED "Knockback Set!");
        }
      }

      public function 
    onDamage(EntityDamageEvent $event) {
        if(
    $event instanceof EntityDamageByEntityEvent){
          
    $event->setKnockback();
        }
      }
    }
     
  6. AshBull

    AshBull Spider Jockey

    Messages:
    31
    You didn't fix that ;) Either import TextFormat as c (for whatever reason) or import TextFormat and change it to TextFormat::RED
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    jasonwynn10 likes this.
Thread Status:
Not open for further replies.
  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.