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

Whats wrong with $event?

Comments in 'Plugin Development' started by Andrey Nazarchuk, Jun 2, 2015.

  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Hello, I am making a plugin, and pocketmine gave me this error:

    Code:
    Parse error: syntax error, unexpected '$event' (T_VARIABLE) in C:\...\Main.php on line 68

    This is code code on line 68:
    PHP:
    private $p $event->getPlayer();
    Thank you!
  2. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Take off private and it should work.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Can you please fix it? Its on the github...I fell like I will break it because I think it needs to be private.
  4. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Pm me.
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    This is not fixed, please, someone help!
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Insert full code :)
  7. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    That is the full code.
    PocketMine stops at that line, so nothing after it is needed.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    So what is variable $event?
    You must define it
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    And it is not full code if you want help so insert full code :)
  10. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    Please, show us your Main.php file. We can't help you, because without showing all your code, we can't figure out the source of the error.
    iksaku and Creeperface like this.
  11. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    That's the problem. He said the plugin is "private" and wants to show the least code he can.
    PEMapModder and HotFireyDeath like this.
  12. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    Maybe the reason of it have error is you need to explain what is $event?
  13. GlaciercreepsMC
    Offline

    GlaciercreepsMC Active Member Plugin Developer

    Joined:
    Jan 21, 2014
    Posts:
    91
    Plugins:
    1
    Minecraft User:
    GlaciercreepsMC
    No, I think he's referring to the "private" in the code, and doesn't understand what the keyword actually does.
    PHP:
    private $p $event->getPlayer();
    iksaku likes this.
  14. Gamecrafter
    Offline

    Gamecrafter Notable Member Plugin Developer

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I know what he is talking about, of course. But he isn't showing the entire code. He could have put the private keyword within a function. That's whh I said he had to put in the full code to assess the error.
  15. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    How in the world do I define $event? Its undefinable...


    Here is the error that happens every time I touch a sign:
    Code:
    00:46:52 [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'SkyWarsPE v0.1': Undefined variable: event on SkyWarsPE\Main
    00:46:52 [NOTICE] UndefinedVariableException: "Undefined variable: event" (E_NOTICE) in "/SkyWarsPE/src/SkyWarsPE/Main" at line 90
    


    OK here is the code, I changed it a little:
    PHP:
        public function onTouch(PlayerInteractEvent $pie){
    [
    line 90]  $pie $event->getBlock()->getId();
                if(
    $pie == 63 or $pie == 68 or $pie == 323){
                    
    $tile $event->getBlock()->getLevel()->getTile(new Vector3($event->getBlock()->getX(), $event->getBlock()->getY(), $event->getBlock()->getZ()));
                        if(
    $tile instanceof Sign){
                            if(
    $tile->gettext[0] == "[SkyWars]" and $tile->gettext[1] == $this->getConfig()->get('arenaworld')){
                                if(
    $this->arenaplayers >= $this->getConfig()->get('neededplayers') and $this->play == false){
                                    
    $player->sendMessage($swm->get("full"));
                                }elseif(
    $this->arenaplayers $this->getConfig()->get('neededplayers') and $this->play == false){
                                    
    $spawn $this->getConfig()->get('player-spawns')[$this->arenaplayers];
                                    
    $player->teleport(new position($spawn[0], $spawn[1], $spawn[2], $this->getServer()->getLevelByName($this->config->get('arenaworld'))));
                                    
    $this->arenaplayers $this->arenaplayers 1;
                                    
    $player->sendMessage($swm->get("started"));
                                        if(
    $this->arenaplayers >= $this->getConfig()->get('neededplayers')){
                                            
    $this->startGame($tile->gettext[1]);
                                        }
                                }elseif(
    $this->play == true){
                                    
    $player->sendMessage($swm->get("started"));
                                }
                            }
                        }
                }
        }
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Use $event instead of the first $pie
    So PlayerInteactEvent $event
    Andrey Nazarchuk likes this.
  17. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Thank you!
    Creeperface likes this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    All variables are definable. It just depends on what way you define it. Please learn PHP. Your concepts are all wrong.
    iksaku and Creeperface like this.
  19. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    When I am learning PHP on codeacademy it feels like it has nothing to do with plugins...at all.
    PEMapModder likes this.
  20. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Because you didn't learn OOP
    PEMapModder and iksaku like this.

Share This Page

Advertisement