Thread: 'else' without 'if' error

Results 1 to 10 of 10
  1. #1 'else' without 'if' error 
    Member
    Join Date
    Oct 2008
    Posts
    347
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Lol.
    I am such a re-noob.
    the coding is } else {
    What does ah do?
    Reply With Quote  
     

  2. #2  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Code:
    if(condition_to_be_met) {
        //Do something.
    } else {
        //Do something else.
    }
    I don't see what you're not understanding?
    Reply With Quote  
     

  3. #3  
    Member
    Join Date
    Oct 2008
    Posts
    347
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by PSNB View Post
    Code:
    if(condition_to_be_met) {
        //Do something.
    } else {
        //Do something else.
    }
    I don't see what you're not understanding?
    This is my coding:
    Code:
     if (!Item.isFullHelm(playerEquipment[playerHat]) && !Item.isFullMask(playerEquipment[playerHat]) && (playerLook[0] != 1))
            			 playerProps.writeWord(0x100 + pBeard);      // Beard
                				else
                          		 		playerProps.writeByte(0);
                    			} else {
                           			 	playerProps.writeWord(-1);
                           		 		playerProps.writeWord(npcId); }
    I don't know how to fix it. Again, the error is 'else' without 'if' } else {
    Reply With Quote  
     

  4. #4  
    Extreme Donator


    Join Date
    Mar 2009
    Age
    29
    Posts
    956
    Thanks given
    29
    Thanks received
    15
    Rep Power
    215
    Quote Originally Posted by Mr. Linksys View Post
    This is my coding:
    Code:
     if (!Item.isFullHelm(playerEquipment[playerHat]) && !Item.isFullMask(playerEquipment[playerHat]) && (playerLook[0] != 1))
            			 playerProps.writeWord(0x100 + pBeard);      // Beard
                				else
                          		 		playerProps.writeByte(0);
                    			} else {
                           			 	playerProps.writeWord(-1);
                           		 		playerProps.writeWord(npcId); }
    I don't know how to fix it. Again, the error is 'else' without 'if' } else {
    } else { does not have an 'if' it has an 'else' as you can see you did

    else
    //code
    } else {
    //other code

    so } else { doesn't really have an if, I WOULD SAY. (IDK)
    Quote Originally Posted by Note
    Why do you quote yourself?
    Reply With Quote  
     

  5. #5  
    Member
    Join Date
    Oct 2008
    Posts
    347
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    What?! D:
    Reply With Quote  
     

  6. #6  
    Member
    Join Date
    Oct 2008
    Posts
    347
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I will give rep to whoever helps DDx
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Sep 2008
    Posts
    2,219
    Thanks given
    148
    Thanks received
    204
    Rep Power
    1570
    Quote Originally Posted by Mr. Linksys View Post
    This is my coding:
    Code:
     if (!Item.isFullHelm(playerEquipment[playerHat]) && !Item.isFullMask(playerEquipment[playerHat]) && (playerLook[0] != 1))
            			 playerProps.writeWord(0x100 + pBeard);      // Beard
                				else
                          		 		playerProps.writeByte(0);
                    			} else {
                           			 	playerProps.writeWord(-1);
                           		 		playerProps.writeWord(npcId); }
    I don't know how to fix it. Again, the error is 'else' without 'if' } else {
    by what you've provided I would assume the last block is executed if another condition failed, so it would be like this
    Code:
    	if (!Item.isFullHelm(playerEquipment[playerHat]) && !Item.isFullMask(playerEquipment[playerHat]) && (playerLook[0] != 1)) {
    		playerProps.writeWord(0x100 + pBeard);
    	} else {
    		playerProps.writeByte(0);
    	}
    } else {
    	playerProps.writeWord(-1);
    	playerProps.writeWord(npcId);
    }



    Reply With Quote  
     

  8. #8  
    Member
    Join Date
    Oct 2008
    Posts
    347
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    It produced the same error..
    Reply With Quote  
     

  9. #9  
    Donator

    Join Date
    Jul 2009
    Posts
    1,452
    Thanks given
    27
    Thanks received
    13
    Rep Power
    69
    I will try to teach you something about if statements, so that you can fix this yourself

    This is a simple if statement:
    Code:
    if (hp > 99) {
    absX == 5000
    absY == 5000
    }
    This pretty much says: IF your hplevel goes above 99, im gonna have to change your co-ords.

    Okay, this is pretty simple. Moving on to else statements:

    This is the same statement, but this version will show a GFX if your hp is not above 99:
    Code:
    if (hp > 99) {
    absX == 5000
    absY == 5000
    }
    else {
    gfx(1800);
    }
    Okay, this code will look if the player has above 99 hp. If the player doesn't have that the code will move on to else, to see what to do if the first statement wasn't do-able.

    Else statements are only for what to do if everything else goes wrong. (If none of the conditions are satisfyed).

    You can also use ELSE IF. They are used if you want it to look for another thing if the above one is not satisfied.
    A code with all this could be:
    Code:
    if (imLaughing == true) {
    Dothis!
    }
    else if (imLaughing != true) {
    DoThis!
    }
    else if (imNotHere == true) {
    Dohis!
    }
    else {
    dontdoanything
    }
    You see, using else if's you can make it look for another thing if the first one didn't go well.
    Else just specifys what to do if no IF's or ELSE IF's are satisfied.

    My teaching skills are bad, and so is my examples.
    I hope you learned something
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Dec 2009
    Age
    30
    Posts
    318
    Thanks given
    1
    Thanks received
    3
    Rep Power
    19
    lol not } else {


    its } else

    thats it
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •