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

FormAPI & array $data question

Discussion in 'Development' started by CupidonSauce173, Jul 20, 2019.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hello, so I have a little question, basically I want to make it so when you do example /plist, there is a form with a list of values in an array in a config.yml, example
    PHP:
    values :
    test
    test1
    test2
    test3
    The values are dynamic, they keep changing while the player play so I cannot use the case x: thingy, basically, I want it to be so if player click button test56 for example, it does send "hey" but if he click the button test23, it say "yo"

    Ik that in FormAPI by Jojoe we can array $data and Ig this is used for strings datas but I got no idea on how to use it

    For now I use that to list all values in `values`

    Code:
            $form->setTitle($langFile->get("values.Title.form"));
            foreach($player_file->get("values") as $values){
    
                $form->addButton($values);
            }
            $form->sendToPlayer($player);
    If someone could help it would be nice, thank you

    EDIT:
    ok so I found a solution, first, make your array database to look like this
    Code:
    values:
    1 - test
    2 - test2
    3 - test3
    4 - test4
    
    Then, in your form class, you will need to foreach your array like that
    Code:
            foreach($values_content as $values){
                $form->addButton($values);
            }
    then, in your form function, add this code
    Code:
                if($data === null){
                    return;
                }
                $values_file= new Config("/path/to/custom/directory/"  . "values_file.yml");
                $values_content= $values_file->get("values");
    
                $player->sendMessage("selected: " . $values_content[$data]);
    Basically $data = the index of your values array
     
    Last edited: Jul 20, 2019
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    I liked this post, because you are one of not many people who provide their solution if they solved the problem by themselves.
     
    CupidonSauce173 and KielKing like this.
  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.