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 VCraft, Apr 8, 2017.

  1. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    So this code:
    PHP:
    public function getData(){
            return 
    $this->data;
        }
       public function 
    onPlayerJoin(PlayerJoinEvent $ev){ //line 809
         
    $player $ev->getPlayer();
         
    $name $player->getName();
         
    $event->setJoinMessage("");
    }
    give me this error:
    Code:
    ParseError: "syntax error, unexpected 'public function onPlayerJoin' (T_STRING), expecting function (T_FUNCTION)" (EXCEPTION) in "/FactionCore/src/VCraft/FactionsCore/Main" at line 809
    help?
     
    Last edited: Apr 8, 2017
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    We need to see all of the code before the snippet you shared to be able to help.
     
    TxnnerOS and Jack Noordhuis like this.
  3. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    First of all, use
    PHP:
     [PHP
    for php and
    Code:
     [CODE] 
    for your code. And I think the issue is that you wrote onPlayerJoin, it should be onJoin if my memory is good
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    Function name can be anything (with exceptions). There is no standard for how to name your listening functions. But I mostly name them like this
    PHP:
    function get_func_name(Event $event): string {
        return 
    "on".substr($class array_reverse(explode("\\"get_class($event)))[0], 0strpos($class"Event"));
    }
     
  5. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Sorry then, did not know that thanks !
     
  6. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    Still the same error
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    As I said, there's nothing to do with your function name. Show few bits of lines above this code.
     
  8. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    Ok
    PHP:
    public function onChat(PlayerChatEvent $event){
         
    $player $event->getPlayer();
         if(isset(
    $this->chat[strtolower($player->getName())])){
         foreach(
    Server::getInstance()->getOnlinePlayers() as $players){
         if(
    $players->hasPermission("staff.chat")){
         
    $players->sendMessage(C::RED."(!) STAFF: ".C::DARK_AQUA."{$player->getDisplayName()}: §f{$event->getMessage()}");
         
    $event->setCancelled(true);
           }
          }
         }
       }
       
      public function 
    welcomeTitle($p){
          
    $p->sendTitle(C::RED."Welcome",C::DARK_AQUA."enjoy your stay");
      }
       
       public function 
    getData(){
            return 
    $this->data;
        }
       
       
       public function 
    on_Player_Join(PlayerJoinEvent $ev){
         
    $player $ev->getPlayer();
         
    $name $player->getName();
         
    $event->setJoinMessage("");  
    }
     
  9. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Is that the whole PHP file? Send the whole PHP file.
     
  10. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    No the file is like 1k lines
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Do you have a class in the whole PHP file?
     
  12. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    The function not is sendTitle(), but yes addTitle()
     
  13. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    It appears that the "public function onPlayerJoin" is being read as a string and not a function, but that seems wrong. I suggest examining that section of the plugin very carefully. Maybe you will find a stray quotation mark or something that is causing the issue. Also, this is more of a PHP issue than a Pocketmine issue, so you may have more luck by looking on StackOverflow or similar websites.
     
  14. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    Your code is
    PHP:
    $event->setJoinMessage("");
    If you're trying to hide the join message you should be using
    PHP:
    $e->setJoinMessage("");
     
  15. Zuruki

    Zuruki Baby Zombie

    Messages:
    118
    GitHub:
    zuruki
    He's using T-Spoon, so it is actually sendTitle(), but obviously you didn't know so it isn't your fault :)
     
  16. VCraft

    VCraft Witch

    Messages:
    60
    GitHub:
    VCraftMCPE
    Ok thanks
     
  17. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    use ghostbin.com to send over 1k lines of code
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Any convention that is clear enough to prevent name collision is OK. For example something that specifies that it is an event handler, and for that event. Therefore conventionally we use the prefixes like "on", "event", "e_", etc., and a simple verb or noun-verb clause to specify the event so that different events won't accidentally have the same name.
    A simpler way of naming is to type random words by telling your cat to jump on your keyboard.
    [​IMG]
     
  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.