ID:887711
 
(See the best response by Albro1.)
Code:
mob
var/tmp/loop_num = 0
verb/rest()
if(src.action=="Resting")
src<<"You stop resting."
src.action="Nothing"
else if(src.action||src.Stamina>=src.MaxStamina && src.Chakra>=src.MaxChakra)
src<<"You don't need to rest yet."
else
src.action="Resting"
can_move = 0
loop_num++
var/my_loop_num = loop_num
while(my_loop_num == loop_num && action == "Resting")
src.Stamina+=5
src.Chakra+=5
icon_state = "rest"
if(src.Stamina>=src.MaxStamina)
src.Stamina=src.MaxStamina
if(src.Chakra>=src.MaxChakra)
src.Chakra=src.MaxChakra
src<<"You're done resting."
src.action="Nothing"
icon_state = ""
sleep(10)


Problem description: No copile errors and when I run it I use the verb it works but when i use some magic (which cost chakra) and try using rest verb and it won't let me it says you don't need to rest yet but it works 1 time when I try do it again after losing some chakra it doesn't could it be the loop var? need some help here.

reset src.action at the end of the loop
how I can reset it? sorry for the question I still learning
src.action="" src.action=null src.action=0 src.action=FALSE

your pick.
Best response
Having action set to "Nothing" still counts as it having a value. Therefore:
if(src.action)

Will be TRUE. Which means that it will stop you from resting.

You can either set action to "" or change your conditional statement to this:
if(src.action != "Nothing" || (src.Stamina>=src.MaxStamina && src.Chakra>=src.MaxChakra))


Note the parenthesis I added for the correct order of operations. As it is now, it would've been read like so:

if src.action has a value, tell them they don't need to rest.
if their stamina is greater than or equal to their max stamina, tell them they don't need to rest.
if their chakra is greater than or equal to their max chakra, tell them they don't need to rest.

My edit will be read like so:

if src.action is not "Nothing", tell them they don't need to rest.
if their stamina is greater than or equal to their max stamina AND their chakra is greater than or equal to their max chakra, tell them they don't need to rest.

If I didn't convey the difference between those as well as I intended, just say so and I will try a different way.
In response to Albro1
I didn't even catch that. But meh. I just looked for where he said the problem was.
Albro1 the first one worked thanks btw who should i give the vote to?o.o cuz NNAAAAHH helped a bit too...
In response to Kizen Harunishi
Either or, we're both correct in our answers. I don't care either way, so go ahead and vote his up.
Ok thx both of you guys ^^