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

Solved Modal form response data values return int instead of string

Discussion in 'Development' started by Eduardo, Sep 1, 2017.

  1. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    I send a `ModalFormRequestPacket` to the client and the modal form shows up correctly, though when the response comes I expect a string, but I'm given an int. This the form data response in the default form it's returned in:

    Code:
    string(4) "[1]
    "
    
    this is after it's decoded:

    Code:
    array(1) {
      [0]=>
      int(1)
    }
    this is the code I use to send the form:
    PHP:
            /**
             *
             * @param Player $player
             *
             * @return bool
             *
             */
            
    public function sendJoinUI(Player $player) : bool{
                    
    $games = ['test''test2'];
                    foreach(
    array_merge(
                                    
    $this->teamTag->gameManager->getGamesWithStatus(Game::STATUS_OPEN),
                                    
    $this->teamTag->gameManager->getGamesWithStatus(Game::STATUS_WAITING)) as $game$games[] = $game->getGameName();
                    if(empty(
    $games)) return false;
                    
    $form $this->getForm($this->teamTag->getMessage('ui.join.formTitle''Join TeamTag', [TextFormat::ESCAPE => '&']));
                    
    $this->addInput($formself::INPUT_TYPE_DROPDOWN, [
                            
    'text'    => $this->teamTag->getMessage('ui.join.dropdownTitle''Select game to join...', [TextFormat::ESCAPE => '&']),
                            
    'options' => $games,
                            
    'default' => 0
                    
    ]);
                    
    $this->requestModalForm($player$form);
                    return 
    true;
            }
    The code I use to debug the response:
    PHP:
            /**
             *
             * @param DataPacketReceiveEvent $event
             *
             * @priority LOWEST
             *
             */
            
    public function dataPacketReceiveEvent(DataPacketReceiveEvent $event){
                    
    $pk $event->getPacket();
                    if(
    $pk instanceof ModalFormResponsePacket){
                            
    var_dump($pk->formData);
                            
    //$this->teamTag->userInterface->handleModalFormResponse($event->getPlayer(), json_decode($pk->formData, true));
                    
    }
            }
     
  2. eDroid

    eDroid Witch

    Messages:
    59
    GitHub:
    edroiid
    i think thats how it works. like arrays it counts the options.

    A - o
    B - x
    C - o

    you would get 1 as the response because B was selected.

    please correct me if im wrong.
     
  3. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    No... If the client chose a value it's supposed to be the same value as the one you sent. Also need this to identify a game by name...
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    They return an array of previous chain of formIds encoded in json. You need to json_decode the return value.
     
    Sandertv likes this.
  5. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    But this is already decoded?
    PHP:
    array(1) {
      [
    0]=>
      
    int(1)
    }
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah, so your question was why they return ints and not strings. Why do you want them to return strings and what should the string contain?
     
    jasonwynn10 likes this.
  7. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Maybe I got the idea of forms wrong, but i intent to use the string to identify a game by name, the string should contain the name of the game the player chose.
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah it's kinda hard because of how minimal the response data is. Assign a unique ID for every type of form you will be having on your server.
    PHP:
    interface Forms{

        const 
    BANMANAGER 1;
        const 
    FEEDBACKFORM 2;
        const 
    STATSFORM 3;
    }
     
  9. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Ah.. that still won't help, I need some kind of way to identify the game a player chose wether it's the name or ID of the game.
     
  10. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    Maybe there's a way if I cache the player and the index/value of each form value, then I can use the int returned from the form data to check the cache and determine which value the player chose. This may be a bit bad but I'll still do it.
     
  11. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    The method above worked. :D
     
  12. chansol

    chansol Spider Jockey

    Messages:
    32
    GitHub:
    ParkChanSol
    /**
    *
    * @param DataPacketReceiveEvent $event
    *
    * @priority LOWEST
    *
    */
    public function dataPacketReceiveEvent(DataPacketReceiveEvent $event){
    $pk = $event->getPacket();
    if($pk instanceof ModalFormResponsePacket){
    var_dump((array) json_decode($pk->formData));
    }
    }
     
  13. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note that it is planned that a modal form API be added into PocketMine core (just like commands API).
    (Still not sure how things can be managed - modal form really sucks; the player can't request the form to start simply by clicking a button, so it doesn't save you the trouble of using the keyboard, so it is entirely meaningless for pocket edition users)
     
    jasonwynn10 likes this.
  14. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    I don't follow - plugins can send forms when players click anything...
     
    jasonwynn10 likes this.
  15. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    But you can't control when that happens. For example, the player may need to reserve a hotbar slot for opening the form.
     
  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.