Why does $form not Work ?

Discussion in 'Plugin Help' started by TheWalkingDrift, Jun 25, 2019.

  1. TheWalkingDrift

    TheWalkingDrift Silverfish

    Messages:
    23
    This is the Problem:

    [14:55:30] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected '$form ' (T_VARIABLE)" (EXCEPTION) in "plugins/teleporter/src/teleporter/teleporter" at line 16

    And this is the code:

    <?php

    namespace teleporter;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\command\CommandSender;
    use pocketmine\command\Command;
    use pocketmine\Player;
    use pocketmine\plugin\Plugin;
    use jojoe77777\FormAPI\SimpleForm;

    class teleporter extends PluginBase implements Listener{

    public function openHelpUI(CommandSender $player) {
    $form = new SimpleForm(function(Player $player, int $data = null) {});
    $form->addbutton("§3Citybuild");
    }
    public function onCommand(CommandSender $sender, string $commandLabel, array $args) {
    switch ($args[0]) {
    case "menu":
    $form->sendToPlayer($player);
    }
    }
    }
     
  2. Gianluxx

    Gianluxx Witch

    Messages:
    61
    GitHub:
    Gianluxx
    This code is a mess.
     
  3. Destroyer57

    Destroyer57 Zombie

    Messages:
    272
    $form = $api->createSimpleForm(function (Player $sender, array $data) {
     
  4. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    This isn't why the thread is for, of course without the api it won't work but the problem is his understanding of avriable scope.
    https://www.php.net/manual/en/language.variables.scope.php should be helping you, when you understood that, there's another problem, how to pass the form with a function ? Well return the form through that function, in your case :
    PHP:
    return $form;
     
  5. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    Saying that is useless as you aren't helping him.
     
    QuiverlyRivalry likes this.
  6. NutXzG

    NutXzG Silverfish

    Messages:
    23
    GitHub:
    NutXzG
    PHP:
    public function Form(Player $player) {
        
    $form = new SimpleForm(function(Player $playerint $data null){
    if(
    $data === null){
    return 
    true;
    }
    case 
    0:
    //code
    break;
    }
    });
    $form->setTitle("Title");
        
    $form->addbutton("§3Citybuild");
    $form->sendToPlayer($player);
    return 
    $form;
      }
      public function 
    onCommand(CommandSender $senderstring $commandLabel, array $args) {
     
    switch (
    $args[0]) {
          case 
    "menu":
            
    $this->Form($player);
    Can Coppy
     

Share This Page

  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.