Hello! The setScale() function takes the float value. I converted the $date["scale"] value from FormApi form. It doesn't work as I need. Please help with my code! Code: static function setSizeForm(Player $player): CustomForm{ $form = new CustomForm(function (Player $player, array $data = null){ if($data === null) return; $scale = floatval($data["scale"]); $player->setScale($scale); }); $form->setTitle("§ы§l§bSetSize"); $form->addStepSlider("Select the size", ["0.5", "0.6", "0.7", "0.8", "0.9", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0"], 5, "scale"); $form->sendToPlayer($player); return $form; }
The Step Slider's value is of type string, which setScale() does not accept. How do I convert it to set the correct size of the skin (entity)?
https://3v4l.org/H9lIj#v8.0.14 It shouldn't. Perhaps you're doing something wrong? Try dumping the data from the form
The value in $data["scale"] is not the label "1.0", what is there is the index that corresponds to "1.0", in this case 5, so the size is set to 5.
By default PHP assigns the indexes ascending: PHP: [0 => "0.5",1 => "0.6",2 => "0.7",3 => "0.8",4 => "0.9",5 => "1.0"]; What formapi returns in the result is the index, in this case for "1.0" it is 5. So what I recommend you do is duplicate your array inside the function that changes the size of the player and change the $scale variable so that the value it has is the corresponding value of the $scales variable. It should be something like this: PHP: $scales = [0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0];$scale = $scales[$data["scale"]];