Hello people! Im back with one of my "code thats really simple but I cant figure it out" questions! Im trying too see if a player has a level, and if so, remove a level, but if the player doesn't have a level,lets say half a bar, then just return and send that player a message. This is what I got atm: Code (Text): if (!(player.getExp() == 0) && player.getExpToLevel() < 0) { player.giveExpLevels(-1)); player.sendMessage("Removed 1 level!"); return true; } else { player.sendMessage("You dont have a level!"); return false; } Additions and/or corrections are very much welcomed! Thanks in advance, Jack!
so what you're doing is making sure their level is under 0, which is pretty impossible and I don't think you want that, I think you're looking for > 0 not < 0, because you're trying to take 1 away from less than 0 which just doesn't work with exp
Yeah, thanks! Even after programming for a couple of years, I still can get those right! I have to use those alligator pictures, showing which ones what. I'll try now
Nope, if the player is under 1, then it still continues, but if the XP is at a precise level, then it will return. Kinda funky. EDIT: Ignore that, it still works, but if its under the level one, it still continues.
Debug the values in your console and check what they are when a player has no XP. Debug is the first step in solving your own problems.
Code (Text): public void a(Player b){ if (b.getLevel() > 0){ b.setLevel(b.getLevel() - 1); } else if (b.getExp() > 0){ b.sendMessage("dank memes"); } }
Hey all, Im back! So, after alot of messing arond, I finally came out with this for anyone else running into this problem also: Code (Text): if (!(player.getExp() == 0) && player.getLevel() >= 1 || player.getLevel() == 1) I know this seems like a bunch of overlapping bunch of code, but I tried compacting it, but it wouldn't work for some odd reason. I declare this post: SOLVED
This is simpler (and might have the intended effect): Code (Java): player.getExp() > 0 || player.getLevel() > 0 I didn't test it.