Adblock breaks this site

Is this right?

Discussion in 'Programming General' started by Pwnography, Dec 15, 2009.

  1. Pwnography

    Pwnography Active Member
    Banned

    Joined:
    Dec 16, 2008
    Posts:
    204
    Referrals:
    0
    Sythe Gold:
    0
    Is this right?

    Is this right? It's been like a year since I actually programmed in Java.
    It's simple, and I did it as a favor for my friend. I'm just not sure if I got it all right.


    Code:
    if (command.equalsIgnoreCase("master") && (playerRights >= 3)) 
    {
    addSkillXP(14000000, 0);
    addSkillXP(14000000, 1);
    addSkillXP(14000000, 2);
    addSkillXP(14000000, 3);
    addSkillXP(14000000, 4);
    addSkillXP(14000000, 5);
    addSkillXP(14000000, 6);
    addSkillXP(14000000, 23);
    sendMessage("Holy has blessed you with pwnage");
    
    
    
    if (command.equalsIgnoreCase("pure") && (playerRights >=3)
    {
    addSkillXP(14000000, 0);
    addSkillXP(14000000, 2);
    addSkillXP(14000000, 3);
    addSkillXP(14000000, 4);
    addSkillXP(123660,  5);
    addSkillXP(14000000, 6);
    sendMessage("Holy has blessed you with pure pwnage");
     
  2. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Is this right?

    Firstly, indent your code, it makes it a whole lot easier to read. Secondly, you never closed your if statements, so this would not work. In addition, you forgot a ) in your second if statement. Also, you may want to add a loop so you don't need to call the methods with such a little change in arguments manually.

    Try:
    Code:
    if (command.equalsIgnoreCase("master") && (playerRights >= 3)) {
        int[] skills = new int[] {
            0, 1, 2, 3, 4, 5, 6, 23
        };
        for(int skillID : skills) {
            addSkillXP(14000000, skillID);
        }
        sendMessage("You are now a master.");
    } else if (command.equalsIgnoreCase("pure") && (playerRights >=3)) {
        int[] skills = new int[] {
            0, 2, 3, 4, 5, 6
        };
        for(int skillID : skills) {
            addSkillXP(14000000, skillID);
        }
        sendMessage("You are now a pure.");
    }
     
  3. deathbal sam

    deathbal sam Apprentice
    Banned

    Joined:
    Sep 25, 2008
    Posts:
    754
    Referrals:
    0
    Sythe Gold:
    0
    Is this right?

    Code:
    if (command.equalsIgnoreCase("master") && (playerRights >= 3)) 
    {
    addSkillXP(14000000, 0);
    addSkillXP(14000000, 1);
    addSkillXP(14000000, 2);
    addSkillXP(14000000, 3);
    addSkillXP(14000000, 4);
    addSkillXP(14000000, 5);
    addSkillXP(14000000, 6);
    addSkillXP(14000000, 23);
    sendMessage("Holy has blessed you with pwnage");
    
    }
    
    if (command.equalsIgnoreCase("pure") && (playerRights >=3)
    {
    addSkillXP(14000000, 0);
    addSkillXP(14000000, 2);
    addSkillXP(14000000, 3);
    addSkillXP(14000000, 4);
    addSkillXP(123660,  5);
    addSkillXP(14000000, 6);
    sendMessage("Holy has blessed you with pure pwnage");
    }
    
    THAT SHOULD WORK FOR A P SERVER
     
  4. Jimmy

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25
    Is this right?

    But the conventions are disgusting, the message delivered to the player isn't helpful in the least, and you can eliminate the need to manually call the same method 14 times with similar arguments with a loop. You also didn't fix the missing ( in the second if() statement.
     
< Community Sources & Tutorials List | [C#] Grand Exchange Price Grabber >


 
 
Adblock breaks this site