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

Solved FormAPI

Discussion in 'Development' started by xXNiceAssassinlo YT, Jun 27, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I am trying to get wat number they selected here is my code

    PHP:
        public function Block(ExonPlayer $player): void{
            
    $api FormAPI::get();
            
    $form $api->createCustomForm(function (ExonPlayer $player$data){
                if(
    $data !== null){
                    
    #if($data[0] == 5){
                        #$player->sendMessage("F");
                    #}
                    
    $player->sendMessage($data);
                }
            });

            
    $form->setTitle(C::YELLOW "---==>" C::AQUA "Test" C::YELLOW "<==---");
            
    $form->addSlider("test"110);
            
    $form->sendToPlayer($player);
        }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Use var_dump($data) to see what it looks like.
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Error:
    PHP:
    Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.1.1'Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type string, array givencalled in phar://C:/Users/xxnic/OneDrive/Desktop/Server/PocketMine-MP.phar/src/pocketmine/Player.php on line 3279 on FormAPI\FormAPI
    [15:57:24] [Server thread/CRITICAL]: TypeError"Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type string, array given, called in phar://C:/Users/xxnic/OneDrive/Desktop/Server/PocketMine-MP.phar/src/pocketmine/Player.php on line 3279" (EXCEPTIONin "src/pocketmine/lang/BaseLang" at line 110
    var dumb:
    PHP:
    array(1) {
      [
    0]=>
      
    float(2)
    }
     
  4. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You get that error because you pass an array to sendMessage(), as you see in the var_dump, $data is an array and on index 0 you have your precious number.

    PHP:
    $player->sendMessage($data[0]);
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    wont work again
    err:
    PHP:
    Could not pass event 'pocketmine\event\server\DataPacketReceiveEvent' to 'FormAPI v1.1.1'Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type stringfloat givencalled in phar://C:/Users/xxnic/OneDrive/Desktop/Server/PocketMine-MP.phar/src/pocketmine/Player.php on line 3279 on FormAPI\FormAPI
    [06:39:55] [Server thread/CRITICAL]: TypeError"Argument 1 passed to pocketmine\lang\BaseLang::translateString() must be of the type string, float given, called in phar://C:/Users/xxnic/OneDrive/Desktop/Server/PocketMine-MP.phar/src/pocketmine/Player.php on line 3279" (EXCEPTIONin "src/pocketmine/lang/BaseLang" at line 110
    code:
    PHP:
        public function Block(ExonPlayer $player): void{
            
    $api FormAPI::get();
            
    $form $api->createCustomForm(function (ExonPlayer $player$data){
                if(
    $data !== null){
                    
    $player->sendMessage($data[0]);
                    
    #var_dump($data);
                
    }
            });

            
    $form->setTitle(C::YELLOW "---==>" C::AQUA "Test" C::YELLOW "<==---");
            
    $form->addSlider("test"110);
            
    $form->sendToPlayer($player);
        }
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Oh, I forgot, you need to put (string) before $data[0] in sendMessage.
     
    jasonwynn10 likes this.
  7. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    change
    PHP:
    $form->addSlider("test"110);
    to
    PHP:
    $form->addSlider("test"1101);
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Why you need 1
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Thanks it worked!
     
  10. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    1 for step
     
  11. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    That's optional, I think the step is 1 by default. Also, we don't even know if OP wants a step of 1.
     
    jasonwynn10 likes this.
  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.