Java Noob Question about ifs and else

Discussion in 'Plugin Development' started by chriztopia, Mar 31, 2013.

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

    chriztopia

    Code:
    if (player.haspermission = "user.admin"){
    int max = this.getConfig().getInt("User.max1");
     
    }else{
    int max = this.getConfig().getInt("User.max2");
    }
    
    if (num  > max){
    }
    
    I am trying to figure out why this would not work? I know its a Java Noob question but it has been bugging me for a few days... The max wont work in num>max.

    Max just can not be found as a variable...
     
  2. Offline

    SugarCraft

    ....
    Code:
    if (player.hasPermission("user.admin"){
    int max = this.getConfig().getInt("User.max1");
     
    }else{
    int max = this.getConfig().getInt("User.max2");
    }
     
    if (num  > max){
    }
     
  3. Offline

    stirante

    I'll explain a little.
    1. '=' is setting, '==' is comparing, '===' is also comparing but as strict equality.
    2. To compare strings don't use '==' or '==='. Use string.equals(anotherString) or string.equalsIgnoreCase(anotherString) for ignoring diffrence between upper and lower case.
    3. To use method add '()' at end of method name. If method needs parameters put them in '()'.
    4. 'haspermission' is not 'hasPermission'. Java is case sensitive.
    5. Local variables in if block are not visible outside that block I think.
     
  4. Offline

    xXMaTTHDXx

    If your defining if they have the node just use if(player.hasPermission("your.node"){
     
  5. Offline

    chriztopia

    and yet none of this answered my question lol. Only the Local Variables in if block are not visible outside that block.
     
  6. Offline

    xXMaTTHDXx

    People are helping you but you don't understand what they are trying to say.
     
  7. Offline

    dcgamingentral

    Code:
    //variables should be in global scope
    public int max;
    public int min;
    ...
    // should be bracket around hasPermission because it's a method
    if (player.hasPermission("user.admin")){
    max = this.getConfig().getInt("User.max1");
    }else{
    max = this.getConfig().getInt("User.max2");
    }
     
    if (num  > max){
    // check
    }
    I would recommend learning Java before making plugins

    Hope it helps.
     
  8. Offline

    ZeusAllMighty11

    You didn't define the variables in the right place.
     
Thread Status:
Not open for further replies.

Share This Page