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

Will this code work?

Comments in 'Plugin Development' started by MyNameIsTriXz, Jan 29, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    PHP:
    $this->games = ["Game1" => ["inGame", *playerobject1*, *playerobject2...], "Game2" => ["inQueue", *playerobject1*, *playerobject2*]];


    foreach(
    $this->games as $game => $players){
    if(
    $this->inQueue($game)){
    if(
    $player instaceof Player){
    $players->sendMessage("Waiting for players...");
    }}
    }


    public function 
    inQueue($game){
    if(
    $game[0] == "inQueue"){
    return 
    true;
    else
    return 
    false;
    }
    What do you think about this way to code and donyou think it will work?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    why don't you test yourself lazy.
  3. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    It should. Tho, I would rather use
    PHP:
    public function inQueue($game){
       return 
    $game[0] === "inQueue";
    }
    than
    PHP:
    public function inQueue($game){
       if(
    $game[0] == "inQueue"){
          return 
    true;
       } else{
          return 
    false;
       }
    }
    Just saying, you had some "{" missing in your code.
    applqpak and PEMapModder like this.
  4. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Okay good, btw else without {} is acceptable
    applqpak and PEMapModder like this.
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Well, "if" is too. Then you still would need to close the "if" statement tho:
    PHP:
    public function inQueue($game){
    if(
    $game[0] == "inQueue"){
    return 
    true;
    }else return 
    false;
    }
    Plus, it only works if you have one argument inside.
    applqpak and MyNameIsTriXz like this.
  6. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Oh okay
  7. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    You don't need the brackets.
    PHP:
    if(true)
       return 
    true;
    else
       return 
    false;
    will work fine
    applqpak, PEMapModder and Vaivez66 like this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Read ALL Posts. He opened "if", which means he either has to close it or remove the bracket. I did not say he needs them, I just told him to close the if statement.
    And still, my first code actually is the easiest, so I don't know why we now have to discuss about the other one. Just use
    PHP:
    public function inQueue($game){
       return 
    $game[0] === "inQueue";
    }
    applqpak and PEMapModder like this.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Proper indentation = bye all curly braces issues
    applqpak likes this.

Share This Page

Advertisement