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

FormAPI error

Discussion in 'Help' started by Levi, Jun 8, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Code:
    [19:30:15] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.1.1': Argument 2 passed to gay\command\warp\WarpCommand::gay\command\warp\{closure}() must be of the type array, null given, called in C:\Users\arjxy\Desktop\pocketmine\plugins\FormAPI-master\src\jojoe77777\FormAPI\FormAPI.php on line 75 on jojoe77777\FormAPI\FormAPI
    [19:30:15] [Server thread/CRITICAL]: TypeError: "Argument 2 passed to gay\command\warp\WarpCommand::gay\command\mine\{closure}() must be of the type array, null given, called in C:\Users\arjxy\Desktop\pocketmine\plugins\FormAPI-master\src\jojoe77777\FormAPI\FormAPI.php on line 75" (EXCEPTION) in "plugin/src/gay/command/warp/WarpCommand" at line 40
    line 40
    PHP:
    $form $api->createSimpleForm(function (Player $player, array $args) {
    //api is 
    $api $this->plugin->getServer()->getPluginManager()->getPlugin("FormAPI");
     
  2. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    1- try this:
    PHP:
    $form $api->createSimpleForm(function (Player $player, array $args) {
    2- if didn't work try to make $api in the top of $form
    3- or why don't try to transform array $args to array $data maybe this will fix the problem.
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i did those and I forgot to say that I only get those errors when i tap on button
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    $api $this->plugin->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createSimpleForm(function (Player $player, array $data) {
                
    $result $data[0];
                if (
    $result === null) {
                    return;
                }
                switch (
    $result) {
                    case 
    0:
                            
    $sender->sendMessage("ok");
                        return;
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Try to remove array word in createsimpleform(
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    nothing happens now..
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Or write ?array
     
  8. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i saw this new thread i didnt know formApi updated
    $form = $api->createSimpleForm(function (Player $player, ?int $result = null) {
     
  9. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The = null is not needed
     
    Levi likes this.
  10. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    not solved what the crap is going on here
    i dont see nothing wrong in my code
    PHP:
    $api $player->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createModalForm(function (Player $sender, array $data) {
                
    var_dump($data);
            });
            
    $form->setTitle("Form Title");
            
    $form->setContent("Text inside form");
            
    $form->setButton1("Button 1");
            
    $form->setButton2("Button 2");
            
    $form->sendToPlayer($player);
    Code:
     [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.1.1': Argument 2 passed to gay\Main::gay\{closure}() must be of the type array, null given, called in C:\Users\arjxy\Desktop\pocketmine\plugins\FormAPI-master\src\jojoe77777\FormAPI\FormAPI.php on line 75 on jojoe77777\FormAPI\FormAPI
    [17:29:00] [Server thread/CRITICAL]: TypeError: "Argument 2 passed to gay\Main::gay\{closure}() must be of the type array, null given, called in C:\Users\arjxy\Desktop\pocketmine\plugins\FormAPI-master\src\jojoe77777\FormAPI\FormAPI.php on line 75" (EXCEPTION) in "core/src/gay/Main" at line 20
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The $data parameter should be nullable. By writing "array $data", you require it to be an array, not null. To allow null or array, you should write "?array $data".
     
  12. AshBull

    AshBull Spider Jockey

    Messages:
    31
    I guess @jojoe77777 does the impossible then
    https://github.com/jojoe77777/FormAPI
    66974792e706e67.png
     
  13. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i did but i still get error
     
  14. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    PHP:
    /** @var FormAPI $api */
            
    $api $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $api->createModalForm(function (Player $player, ?array $result) {
                if (
    $result === null) {
                    return;
                }
                if(
    $result == true){
                   
    $player->sendMessage("its true");
                }
            });
            
    $form->setButton1("ook");
            
    $form->setButton2("not ok");
            
    $form->sendToPlayer($player);
    Code:
    {closure}() must be of the type array or null, boolean given
     
  15. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    PHP:
            $form $api->createModalForm(function (Player $playerint $data null) {
     
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It should be ?(Player $player, bool $data). Please don't post answers if you don't know are just guessing (without disclaiming).
     
    Last edited: Jun 30, 2018
    Levi likes this.
  17. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    But i tried it and it is working
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    createModalForm can give true or false, so it should be bool.
    createSimpleForm can give an int (the selected index) or null (closed), so it should be ?int.
    createCustomForm can give null (closed) or an array containing the returned data, so it should be ?array.
     
  19. AshBull

    AshBull Spider Jockey

    Messages:
    31
    createSimpleForm and createCustomForm can also give the label, which is whatever type you set it as previously
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    createSimpleForm: oops right, I made that change myself and I forgot it :(
    createCustomForm still returns an array.
     
  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.