Bobafart
12-30-2008, 07:53 PM
I have an IF ELSE and I do not understand the logic JS is using. The code is regarding a player level system. The player needs a certain number of experience points in order to gain a level.
In the case where the player does not have enough XP to gain the level I have the following IF ELSE conditional:
if(playerXP<playerXPNeededNextLevel){ // player doesnt have enough XP to level
document.getElementById('pushbutton').innerHTML='<img src="http://www.domain.com/img/icons/icon_levelmeupdisabled.gif" />';
document.getElementById('playerNextLevelStatus').style.color = 'red';
}else{
// level up the user
}
Interestingly if the playerXP = 99 XP and the XP needed to level is 25 XP or 50XP everything works fine (the player levels and the "Level Up" icon button doesn't disable.
However, if the player has XP with the first number of the XP value being lower than the XP needed to level then the IF conditional is satisfied and the icon is disabled.
Example 1:
playerXP = 561
playerXPNeededNextLevel = 51
- pass - this makes sense
------------------------
Example 2:
playerXP = 461
playerXPNeededNextLevel = 51
- fail! (why? because 5 > 4 ) - this is the only pattern I can identify
-------------------------
Example 3:
playerXP = 461000000000000000
playerXPNeededNextLevel = 51
- fail! (why? because 5 > 4 )- this is the only pattern I can identify
strange, no?
I use alert()'s to check and double check for errors.. I can't find any.... the logic isn't making sense.
In the case where the player does not have enough XP to gain the level I have the following IF ELSE conditional:
if(playerXP<playerXPNeededNextLevel){ // player doesnt have enough XP to level
document.getElementById('pushbutton').innerHTML='<img src="http://www.domain.com/img/icons/icon_levelmeupdisabled.gif" />';
document.getElementById('playerNextLevelStatus').style.color = 'red';
}else{
// level up the user
}
Interestingly if the playerXP = 99 XP and the XP needed to level is 25 XP or 50XP everything works fine (the player levels and the "Level Up" icon button doesn't disable.
However, if the player has XP with the first number of the XP value being lower than the XP needed to level then the IF conditional is satisfied and the icon is disabled.
Example 1:
playerXP = 561
playerXPNeededNextLevel = 51
- pass - this makes sense
------------------------
Example 2:
playerXP = 461
playerXPNeededNextLevel = 51
- fail! (why? because 5 > 4 ) - this is the only pattern I can identify
-------------------------
Example 3:
playerXP = 461000000000000000
playerXPNeededNextLevel = 51
- fail! (why? because 5 > 4 )- this is the only pattern I can identify
strange, no?
I use alert()'s to check and double check for errors.. I can't find any.... the logic isn't making sense.