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

get $data from slider FormAPI

Discussion in 'Facepalm' started by NoWlanDudeXd, Mar 14, 2018.

  1. NoWlanDudeXd

    NoWlanDudeXd Creeper

    Messages:
    1
    public function haste(Player $sender){
    $form = $this->createCustomForm(function (Player $player, array $data){

    $form->setTitle(TF::AQUA."Driller");
    $form->addSlider(TF::YELLOW."Level",1,2);
    $form->sendToPlayer($sender);
    }
     
  2. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
  3. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
     
  4. Seeker

    Seeker Spider Jockey

    Messages:
    45
    GitHub:
    seeker-devs
    thanks for your incredibly valuable contribution to this thread.
    I'm not going to 'code' for you because uhm... you should learn it yourselves but I'm just gonna make a 'skeleton' of it (or explain it in other words).
    a) Declare null as $data value first.
    b) Your code is broken.
    c) check if $data === null ('===' checks if they are the same time and $data is equal to null which will be True if they exit the form without 'interacting' with it in any way). if you want it to do nothing if the user does nothing, simply return; return ends the execution of the program aka exits the form without doing anything in this case.
    d) instead of using
    PHP:
    $formvariable->sendToPlayer($playerobjectvariable);
    (which is a depracted method by the way) use
    PHP:
    $playerobjectvariable->sendForm($formvariable);
    e) if this was in plugin-help, I'd say 'learn php' but here's a facepalm :facepalm:... add '});' after function. Please stop coding on mobile and using github's editor, get a good IDE.
    But please.. even though this is in facepalm... learn php and stop using SoloLearn of CodeCademy. I appreciate those sites (or whatever, I don't use them anyways) but PHP has a good manual for learning how to code in PHP.
    have a nice day and wash your hands!
    ALSO DON'T BE LIKE OTHERS AND MARK THIS AS SOLVED IF THIS GETS SOLVED..
     
  5. Seeker

    Seeker Spider Jockey

    Messages:
    45
    GitHub:
    seeker-devs
    also yes, sorry for legit spamming this thread, but in an array, the first value is considered as 0. I'm explaining in non-techy words but this is hard..
    OKAY, heres's an example:
    PHP:
    $seeker = array("Seeker""Thread");
    //array(); is to supposed php 5 too, and is in php7 too
    echo("Who will win? " $seeker[0] . " or this " $seeker[1]);
    //Outputs Who will win? Seeker or this Thread
    Typing on phone is hard but I wish you learnt somethig from this..
    In your case, your first 'addSlider()' will be considered as '$data[0]'
     
  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.