Hi, i'm new at pmmp and i used this plugin called FormAPI, and im trying to get $data when making form. Here's the code PHP: public function ChooseClass(Player $player){ $rpgClass = [TextFormat::DARK_GRAY . 'Rogue', TextFormat::AQUA . 'Mage', TextFormat::YELLOW . 'Warrior']; $form = $this->form->createCustomForm(function (Player $sender, array $data) { $sender->sendMessage($rpgClass[$data[0]]); }); // Sends all data to console $form->setTitle(TextFormat::GOLD . "Select Your Class"); $form->addDropdown("Class", $rpgClass); $form->sendToPlayer($player);} I cant send the message to the player because the $rpgClass variable is outside. so, How to get the $data outside the Function inside the $form Sorry for my bad english
You will need to explain what is the API, so change with this: PHP: public function ChooseClass(Player $player){ $rpgClass = [TextFormat::DARK_GRAY . 'Rogue', TextFormat::AQUA . 'Mage', TextFormat::YELLOW . 'Warrior']; $api = $this->getServer()->getPluginManager()->getPlugin("FormAPI"); $form = $api->createCustomForm(function (Player $sender, array $data) { $sender->sendMessage($rpgClass[$data[0]]); }); // Sends all data to console $form->setTitle(TextFormat::GOLD . "Select Your Class"); $form->addDropdown("Class", $rpgClass); $form->sendToPlayer($player);}
i Already use the API on __construct PHP: public function __construct(Main $main){ $this->form = $main->getForm();} and the form is working. the problem is, i cant get the $data after the player submit the form this is getForm() function PHP: public function getForm(){ $this->form = new FormAPI($this); return $this->form;} i didnt use FormAPI as new plugin, i just add it to my code
i can use PHP: public function ChooseClass(Player $player){ $form = $this->form->createCustomForm(function (Player $sender, array $data) { var_dump($data); }); $form->setTitle(TextFormat::GOLD . "Select Your Class"); $form->addDropdown("Class", $this->getClass()); $form->sendToPlayer($player);} but, i want to use the $data outside the $form variable
Its not, i use var_dump here PHP: public function ChooseClass(Player $player){ $form = $this->form->createCustomForm(function (Player $sender, array $data) { var_dump($data); }); $form->setTitle(TextFormat::GOLD . "Select Your Class"); $form->addDropdown("Class", $this->getClass()); $form->sendToPlayer($player);} i just wanna know if i could use like this PHP: public function ChooseClass(Player $player){ $form = $this->form->createCustomForm(function (Player $sender, array $data) { }); $form->setTitle(TextFormat::GOLD . "Select Your Class"); $form->addDropdown("Class", $this->getClass()); $form->sendToPlayer($player); var_dump($data);}
PHP: $form = $this->form->createCustomForm(function (Player $sender, array $data) use ($rpgClass) { $sender->sendMessage($rpgClass[$data[0]]); });