If, then, and else not working properly

I’m trying to make a script for a pokemon’s exp. When it has enough, it will display the alert telling the user that it has leveled up, but when it doesn’t have enough, it just displayers the current exp/limit. The problem is that even if exp is less than the limit, it goes through the level up process instead of displaying the exp/limit. I’ve looked through this many times and still can’t figure out what’s wrong.

Here’s the script:


--levels
set pika to "rarr"
set limit to 20 as text
set level to 1 as text
set exp to 0
set expamount to (random number from 3 to 7)
display alert pika & " got " & expamount & " exp!"
exp + expamount
set exp to result as text
--display alert exp
--display alert limit
if exp is less than limit then
	display alert exp & "/" & limit
else
	display alert pika & " leveled up!"
	level + 1
	set level to result as text
	exp - limit
	set exp to result as text
	display alert pika & " is now level " & level
	limit + 10
	set limit to result as text
	
end if

I’m not sure what you’re trying to do, but using result like that nearly always leads to disaster. And you shouldn’t be coercing limit, level and exp to strings – that throws out your comparisons.

This should get you started:

set pika to "rarr"
set limit to 20
set level to 1
set exp_ to 0
set expamount to (random number from 3 to 7)
display alert pika & " got " & expamount & " exp!"
set exp_ to exp_ + expamount
if exp_ is less than limit then
	display alert (exp_ as text) & "/" & limit
else
	display alert pika & " leveled up!"
	set level to level + 1
	set exp_ to exp_ - limit
	display alert pika & " is now level " & level
	set limit to limit + 10
end if

(I’m using exp_ because exp conflicts with some terminology on my Mac.)

Thank you so much! ^.^