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

How to work an if statement to FormAPI switch?

Discussion in 'Development' started by NickteeChunky, Jul 21, 2019.

  1. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    So I'm adding a result to switch but whenever I add an if statement, it doesn't work and acts as if whatever is below isn't there. When I end the if statement and run somethint else by itself, it works fine. I'm very confused, please help me.
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    can you provide your code?
     
  3. NickteeChunky

    NickteeChunky Witch

    Messages:
    64
    GitHub:
    nickteechunky
    PHP:
        public function onCommand(CommandSender $senderCommand $cmdstring $label, array $args): bool{
            
    $formapi $this->getServer()->getPluginManager()->getPlugin("FormAPI");
            
    $form $formapi->createSimpleForm(function (Player $playerint $data null){
                        
    $result $data;
                        if (
    $result === null) {
                            return;
                        }
                        
                        if(
    $result === 1) {           
                           
    $chance mt_rand(0,1); # For test purposes
                           
    if ($chance === 1) {
                               
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), 'enchant  '.$sender->getName().' efficiency 1');
                        
                           }
                        }
                    
                        switch (
    $result) {
                            case 
    0:
                            break;
                        }
                    
                        return;
        } );
                
            
    $form->setTitle("Random Enchants");
            
    $form->addButton("TEST");
            
    $form->sendToPlayer($sender);
            return 
    true;
        }
    }
     
  4. Mr174

    Mr174 Baby Zombie

    Messages:
    187
    GitHub:
    mr174
    PHP:
    if ($result === 1){
    $chance mt_rank(0,1);
    switch (
    $chance){
    case 
    1:
    $this->getServer()->dispatchCommand(new ConsoleCommandSender(), 'enchant  '.$sender->getName().' efficiency 1');
    break;
    }
    }
    I dont think you need that other switch
     
  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.