setScale() help

Discussion in 'General discussion' started by Sergio2007, Jan 14, 2022.

  1. Sergio2007

    Sergio2007 Spider

    Messages:
    6
    GitHub:
    sergiy-morning
    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;
      }
     
  2. Sergio2007

    Sergio2007 Spider

    Messages:
    6
    GitHub:
    sergiy-morning
    Help, I'm powerless.
     
    Last edited: Jan 15, 2022
  3. Sergio2007

    Sergio2007 Spider

    Messages:
    6
    GitHub:
    sergiy-morning
    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)?
     
  4. minijaham

    minijaham Skeleton

    Messages:
    809
    GitHub:
    minijaham
    Try (float) tag
     
    Sergio2007 likes this.
  5. Sergio2007

    Sergio2007 Spider

    Messages:
    6
    GitHub:
    sergiy-morning
    It rounds 0.5 to 0.
     
  6. Sergio2007

    Sergio2007 Spider

    Messages:
    6
    GitHub:
    sergiy-morning
    After I set this slider position:

    [​IMG]

    The skin size will be set to 5, i.e. rounded up:

    [​IMG]
     
  7. minijaham

    minijaham Skeleton

    Messages:
    809
    GitHub:
    minijaham
    https://3v4l.org/H9lIj#v8.0.14

    It shouldn't. Perhaps you're doing something wrong? Try dumping the data from the form
     
  8. IvanCraft623

    IvanCraft623 Slime

    Messages:
    99
    GitHub:
    IvanCraft623
    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.
     
    Sergio2007 likes this.
  9. IvanCraft623

    IvanCraft623 Slime

    Messages:
    99
    GitHub:
    IvanCraft623
    By default PHP assigns the indexes ascending:
    PHP:
    [
    => "0.5",
    => "0.6",
    => "0.7",
    => "0.8",
    => "0.9",
    => "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.50.60.70.80.91.01.11.21.31.41.51.61.71.81.92.0];
    $scale $scales[$data["scale"]];
     
    Sergio2007 likes this.

Share This Page

  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.