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($form, self::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)); } }
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.
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...
They return an array of previous chain of formIds encoded in json. You need to json_decode the return value.
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?
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.
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;}
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.
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.
/** * * @param DataPacketReceiveEvent $event * * @priority LOWEST * */ public function dataPacketReceiveEvent(DataPacketReceiveEvent $event){ $pk = $event->getPacket(); if($pk instanceof ModalFormResponsePacket){ var_dump((array) json_decode($pk->formData)); } }
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)
But you can't control when that happens. For example, the player may need to reserve a hotbar slot for opening the form.