Is this right?

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

Is this right?
  1. Unread #1 - Dec 15, 2009 at 9:17 PM
  2. Pwnography
    Joined:
    Dec 16, 2008
    Posts:
    204
    Referrals:
    0
    Sythe Gold:
    0

    Pwnography Active Member
    Banned

    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");
     
  3. Unread #2 - Dec 16, 2009 at 12:56 AM
  4. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    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.");
    }
     
  5. Unread #3 - Dec 16, 2009 at 1:30 AM
  6. deathbal sam
    Joined:
    Sep 25, 2008
    Posts:
    754
    Referrals:
    0
    Sythe Gold:
    0

    deathbal sam Apprentice
    Banned

    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
     
  7. Unread #4 - Dec 16, 2009 at 10:49 AM
  8. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    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 >

Users viewing this thread
1 guest


 
 
Adblock breaks this site