Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Optional commands

Comments in 'Plugin Development' started by zombie_Power, Oct 27, 2015.

Thread Status:
Not open for further replies.
  1. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Greetings,

    I am in a bit of trouble understand, how I might make $arg[0] optional.

    For example: /ban [player/ip] (any one of these as optional)

    Regards,
    Zombie_Power
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    PHP:
    if(isset($args[0])){
        
    # If player has added first argument
    } else {
        
    # If not
    }

  3. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Would I do it twice? or just do $ban || $ip ?
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    What do you mean?
    PHP:
    if(isset($args[0])){
        if(
    $args[0] === "ip"){
            
    //Do your stuff
        
    }
    }
    Or use switch-case. If you don't know how to use switch case, #ReadPHPDocs
  5. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    I do know how to switch cases, however, my particular question is that, how can I make either the name or the ip optional.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    optional? Use switch-case 'default' option, so you can set a default response.
    zombie_Power likes this.
  7. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Thanks :)
    Legoboy0215 likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement