ID:262568
 
Code:
mob
verb
Meditate()
if(usr.med==0)
icon_state = "Meditate"
sleep(15)
usr.MHP+=rand(1,3)
usr.HP=usr.MHP
else

mob
verb
stopMeditate()
if(usr.med==1)
icon_state = ""
else


Problem description:
ok, when you click Meditate, it works, it changes the icon and stuff, but when you click stop meditating, it doesn't stop, also, the meditate won't go into a loop
anyone know the problem?
Dragon warrior2662 wrote:
Code:
> mob
> verb
> Meditate()
> if(usr.med==0)
> icon_state = "Meditate"
> sleep(15)
> usr.MHP+=rand(1,3)
> usr.HP=usr.MHP
> else
>
> mob
> verb
> stopMeditate()
> if(usr.med==1)
> icon_state = ""
> else
>

Problem description:
ok, when you click Meditate, it works, it changes the icon and stuff, but when you click stop meditating, it doesn't stop, also, the meditate won't go into a loop

I see several problems.

- Are you supposed to be continually gain bonuses for meditation? If so, you need a loop.

- You have empty else clauses!

- You never set usr.med to 1 when you meditate, so as far as the game is concerned you're not meditating.

- Don't use usr!

I think it could be better if it were as such:

mob/verb
Meditate()
if(!med)
med = 1
icon_state = "Meditate"
do
sleep(15)
var/bonus = rand(1,3)
MHP += bonus
HP += bonus
while(src && med)
else
src << "Already Meditating!"

Stop_Meditate()
if(med)
med = 0
icon_state = ""
else
src << "Not Meditating!"


Try that. (But PLEASE don't copy & paste. Read through and learn :| )

Also, you're supposed to wait 24 hours before bumping your message. Consider yourself warned by the almighty non-Mod XD

Hiead
In response to Hiead
thanks a lot for helping me, but I am curious, why shouldn't I use usr?
In response to Dragon warrior2662
usr is not always guaranteed to reference what you think it does. By using src, you know that src references the function's calling parent. http://www.byondscape.com/ascape.dmb/LummoxJR.2002-1104/ Explains in more detail.

Though usr is valid in verbs, it is a very bad habit to pick up on. Avoid using usr whenever you can replace it with src or some other reference.

Hiead
In response to Hiead
Hiead wrote:
usr is not always guaranteed to reference what you think it does. By using src, you know that src references the function's calling parent. http://www.byondscape.com/ascape.dmb/LummoxJR.2002-1104/ Explains in more detail.

Though usr is valid in verbs, it is a very bad habit to pick up on. Avoid using usr whenever you can replace it with src or some other reference.

Hiead

Actually, it's completely 100% valid in verbs. It doesn't matter. He does need to learn to do if( !Exp ) if he wants to check against null or if( Exp ) for 1, non-null, etc. ( Boolean expressions ONLY! )