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

I have a problem with FormAPI

Discussion in 'Development' started by Minetron26, Sep 12, 2018.

  1. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Hello, from some updates of the PocketMine API the Plugins that I have done that require FormAPI do not do their job, like this:
    PHP:
    public function openTestForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $playerint $data null){
                    
    $result $data;
                    if(
    $result === null){
                          return 
    true;
                    }
                    switch(
    $result){
                        case 
    "0";
                                 
    $player->sendMessage("The Form is working correctly");
                        break;
                        }
                    
                    
                });
                
    $form->setTitle("Test");
                
    $form->setContent(T::GREEN."Press the button");
                
    $form->addButton("1");
                
    $form->sendToPlayer($player);
                return 
    $form;
            }
    And when will I have clicked on the "1" button, absolutely nothing happens, nor does it give any errors in the console, please help me, tell me what happens.
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Result should be int
     
  3. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Yes, I changed the result to int but nothing happened, still does not send the message to the player:
    PHP:
    public function openTestForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $playerint $data null){
                    
    $result $data;
                    if(
    $result === int){
                          return 
    true;
                    }
                    switch(
    $result){
                        case 
    "0";
                                 
    $player->sendMessage("The Form is working correctly");
                        break;
                        }
                    
                    
                });
                
    $form->setTitle("Test");
                
    $form->setContent(T::GREEN."Press the button");
                
    $form->addButton("1");
                
    $form->sendToPlayer($player);
                return 
    $form;
            }
     
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    case "0";

    should be

    case 0:
     
    Minetron26 likes this.
  5. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    It still does not work
     
  6. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    No, don't do that. Do you want to see the result of that being used?
    Code:
    [19:49:45] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.2.0': Use of undefined constant int - assumed 'int' (this will throw an Error in a future version of PHP) on jojoe77777\FormAPI\FormAPI
    [19:49:45] [Server thread/CRITICAL]: ErrorException: "Use of undefined constant int - assumed 'int' (this will throw an Error in a future version of PHP)" (EXCEPTION) in "TestProject/src/Aericio/TestProject/Commands/TestCommand" at line 67
    I've just tested your original code and it works fine. Ensure that you are:
    - calling it properly
    - chat is not muted
    - FormAPI is installed

    Additionally, add some beautiful checks :)
     
  7. AkmalFairuz

    AkmalFairuz Spider Jockey

    Messages:
    25
    GitHub:
    akmalfairuz
    I think this code working, try this
    Code:
    public function openTestForm($player){
            $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            $form = $api->createSimpleForm(function (Player $player, array $data){
                    $result = $data[0];
                    if($result === int){
                          return true;
                    }
                    switch($result){
                        case 0:
                                 $player->sendMessage("The Form is working correctly");
                        break;
                        }
                    
                    
                });
                $form->setTitle("Test");
                $form->setContent(T::GREEN."Press the button");
                $form->addButton("1");
                $form->sendToPlayer($player);
                
            }
    
     
  8. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    What exactly are you trying to accomplish with this form?

    Again, revert the "if($result === int){}" back to "if($result === null){}"
     
  9. SmartLord

    SmartLord Spider

    Messages:
    8
    GitHub:
    smartlord
    This code working
    PHP:
        public function openTestForm($player){
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $playerint $data null){
                
    $result $data;
                if(
    $result === null){
                    return;
                }
                switch(
    $result){
                    case 
    0;
                        
    $player->sendMessage("The Form is working correctly");
                        return;
                    break;
                }
            });
            
    $form->setTitle("Test");
            
    $form->setContent("Press the button");
            
    $form->addButton("1");
            
    $form->sendToPlayer($player);
            return 
    $form;
        }
     
    xXNiceAssassinlo YT likes this.
  10. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    No, the original code does not work, the form is opened but at the moment of pressing the button nothing happens.
    (Working in API 3.2.0)
     
  11. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    He has string on case
     
  12. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    Could you send me your plugin? That would be more helpful.
     
    Minetron26 likes this.
  13. Minetron26

    Minetron26 Witch

    Messages:
    55
    GitHub:
    minetron26
    Okey
     
  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.