Help with booleans

Discussion in 'Plugin Development' started by migsthegod, Jun 10, 2012.

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

    migsthegod

    Hi, im pretty new and i'm having a problem using a command arg that checks a boolean.

    I first have this:
    Code:
    public boolean spleeferz = false;
    And this command checks the boolean, if event is already off, its supposed to say "stop what?"
    Code:
            else if (args[0].equalsIgnoreCase("stop")) {
                if (sender.hasPermission("eidos.spleefstop")) {
                   
                    if (spleeferz=false){
                        sender.sendMessage("Stop what? No games currently active");
                    }
                    else {
                        Bukkit.broadcastMessage("§8[§dEIDOS §4SPLEEF§8] §eSpleef session has ended!");
                        spleeferz=false;
                        spleeferzjoin=false;
                    }
                }
                else {
                    sender.sendMessage("No permission!");
                }
            }
    Problem is, it keeps saying "spleef session as ended" even if boolean "spleeferz" is false.
    Any ideas?

    i just tried this:

    Code:
      spleeferz=false;
                    if (spleeferz=false){
                        sender.sendMessage("Stop what? No games currently active");
                    }
                    else {
                        Bukkit.broadcastMessage("§8[§dEIDOS §4SPLEEF§8] §eSpleef session has ended!");
                    }
    but still getting the ELSE clause..
    i must be doing something wrong

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  2. Offline

    Suprem20

    Use double equals when doing verifications in the if clause.
     
  3. Offline

    Neodork

    Code:
    if (spleeferz=false){
    You should make sure it looks like:

    Code:
    if (spleeferz==false){

    == means Equals

    If you do this everything should be fine.
     
  4. Offline

    migsthegod

    *Facepalm

    Thanks guys it works now :)
     
  5. Offline

    theguynextdoor

    Although may i recommend that instead of using '== false' that you use !boolean value

    So in your example it would be

    Code:java
    1. if(!spleeferz){
    2. // It's false
    3. } else {
    4. // It's true
    5. }


    Once you get used to it, it is faster and less code and not to mention easier to read
     
Thread Status:
Not open for further replies.

Share This Page