ID:264512
 
Code:
    proc
meditate()
if(usr.meditate==0)
usr.powerlevel += 0
usr.stamina -= 0
usr.maxki+= 0
if(usr.meditate == 1)
usr.stamina -= rand(4,7)
usr.random = rand(1,4)
if(usr.random ==4)
usr.will += 1
usr.maxpowerlevel += rand(25,250)
usr.maxki += rand(1,5)
if(usr.random == 3)
usr.powerlevel += rand(50,500)
if(usr.random == 2)
usr << "<b><font size = 2>You feel more honor enter your blood."
usr.maxki += rand(2,8)
if(usr.random == 1)
usr << "<b><font size = 2>You get more will to fight."
usr.will += 2
if(usr.stamina <= 5)
usr << "<FONT COLOR=White><b>You feel to tired.."
usr.meditating =0
// usr.FlightLearn()
// usr.AuraMake()
sleep(50)
usr.meditate()


Problem description:

I just coded this a few minutes ago and the program is not working.Am i using the random() wrongly? because when i meditate nothing happens.
Tales Number TwO wrote:
Code:
>   proc/meditate()
> while(usr.meditate)
> sleep(50)
> if(usr.meditate==0)
> usr.powerlevel += 0
> usr.stamina -= 0
> usr.maxki+= 0
> world<<"Meditate: 0."
> else if(usr.meditate == 1)
> world<<"Meditate: 1."
> usr.stamina -= rand(4,7)
> usr.random = rand(1,4)
> if(usr.random ==4)
> world<<"Random: 4."
> usr.will += 1
> usr.maxpowerlevel += rand(25,250)
> usr.maxki += rand(1,5)
> if(usr.random == 3)
> world<<"Random: 3."
> usr.powerlevel += rand(50,500)
> if(usr.random == 2)
> world<<"Random: 2."
> usr << "<b><font size = 2>You feel more honor enter your blood."
> usr.maxki += rand(2,8)
> if(usr.random == 1)
> world<<"Random: 1."
> usr << "<b><font size = 2>You get more will to fight."
> usr.will += 2
> if(usr.stamina <= 5)
> usr << "<FONT COLOR=White><b>You feel to tired.."
> usr.meditating =0
> // usr.FlightLearn()
> // usr.AuraMake()
>

Problem description:

I just coded this a few minutes ago and the program is not working.Am i using the random() wrongly? because when i meditate nothing happens.

First: Don't call a proc inside itself. That is bad. It doesn't allow the first proc to finish and ends up infinitely calling the same proc over and over, and as far as the program is concerned all of those procs never finish (until the player stops meditating, then they all will finish), which will ultimately cause a crash if they do it long enough.

Second: I added debugging messages so you can see where your proc is going wrong. Solving a problem like this can be easily handled in steps.

1: At the beginning, add a message saying "Proc started" or whatever. Something so you know that your proc is in fact being called.

2: At each point where the code branches (any if()'s, other proc calls, etc) add another message saying "Proc is at stage X", letting yourself know it reached that point.

Continue doing the above until you find out where your proc is stopping, and then you can try to figure out what is causing it to stop there.
Unless it conflicts with something else you might have, I recommend making the meditate proc /mob, so that you don't have to place usr in front of everything.

Also, try using rand() in switch() instead of overusing usr like that.


switch(rand(1,5))
if(1)
// so and so
if(2)
// so and so
// etc.
In response to AJX
nope nothing appears to happen when i use the verb, all it says is that i begin meditating but nothing happens.
Here is the verb, if it helps
    verb
Meditate()
set name="Meditate"
set category="Training"
if(usr.flight==1||usr.resting==1||usr.blocking==1)
usr << "You are already doing something!"
return
if(usr.meditating==1)
usr << "You stop Meditating"
usr.meditating=0
usr.icon_state=""
usr.move=1
else
usr << "You Begin meditating"
usr.icon_state="meditate"
usr.move =0
meditate()
usr.meditating=1
sleep(10)
In response to Tales Number TwO
Tales Number TwO wrote:
nope nothing appears to happen when i use the verb, all it says is that i begin meditating but nothing happens.
Here is the verb, if it helps
>               meditate()
> usr.meditating=1
>


You are calling meditate() before setting meditating=1. The part after that doesn't happen until the proc already finishes. Switch those two lines.
In response to AJX
nope i am still not getting nothing, i just start all over again
In response to AJX
AJX wrote:
First: Don't call a proc inside itself. That is bad. It doesn't allow the first proc to finish and ends up infinitely calling the same proc over and over, and as far as the program is concerned all of those procs never finish (until the player stops meditating, then they all will finish), which will ultimately cause a crash if they do it long enough.

There are plenty of valid reasons to call a proc inside itself. The basic merge sort algorithm does this, as does quicksort.

The key thing is that the recursive chain is terminating.
In response to AJX
i solved my problem i had put in he verb usr.med=1 but in the proc i used meditating=1.
In response to AJX
AJX wrote:
Tales Number TwO wrote:
Code:
> >     proc/meditate()
> > while(usr.meditate)
> > sleep(50)
> > if(usr.meditate==0)
> > usr.powerlevel += 0
> > usr.stamina -= 0
> > usr.maxki+= 0
> > world<<"Meditate: 0."
> > else if(usr.meditate == 1)
> > world<<"Meditate: 1."
> > usr.stamina -= rand(4,7)
> > usr.random = rand(1,4)
> > if(usr.random ==4)
> > world<<"Random: 4."
> > usr.will += 1
> > usr.maxpowerlevel += rand(25,250)
> > usr.maxki += rand(1,5)
> > if(usr.random == 3)
> > world<<"Random: 3."
> > usr.powerlevel += rand(50,500)
> > if(usr.random == 2)
> > world<<"Random: 2."
> > usr << "<b><font size = 2>You feel more honor enter your blood."
> > usr.maxki += rand(2,8)
> > if(usr.random == 1)
> > world<<"Random: 1."
> > usr << "<b><font size = 2>You get more will to fight."
> > usr.will += 2
> > if(usr.stamina <= 5)
> > usr << "<FONT COLOR=White><b>You feel to tired.."
> > usr.meditating =0
> > // usr.FlightLearn()
> > // usr.AuraMake()
> >

Problem description:

I just coded this a few minutes ago and the program is not working.Am i using the random() wrongly? because when i meditate nothing happens.

First: Don't call a proc inside itself. That is bad. It doesn't allow the first proc to finish and ends up infinitely calling the same proc over and over, and as far as the program is concerned all of those procs never finish (until the player stops meditating, then they all will finish), which will ultimately cause a crash if they do it long enough.

Second: I added debugging messages so you can see where your proc is going wrong. Solving a problem like this can be easily handled in steps.

1: At the beginning, add a message saying "Proc started" or whatever. Something so you know that your proc is in fact being called.

2: At each point where the code branches (any if()'s, other proc calls, etc) add another message saying "Proc is at stage X", letting yourself know it reached that point.

Continue doing the above until you find out where your proc is stopping, and then you can try to figure out what is causing it to stop there.
I see what you are saying and i think i might have done it here. this is my new code and it works, but when i add the while() it Crashes when i click meditate in the game.

    proc
meditate()
while(usr.meditating)
sleep(50)
if(usr.meditating==0)
usr.powerlevel += 0
usr.stamina -= 0
usr.maxki+= 0
if(usr.meditating == 1)
switch(rand(1,5))
if(1)
usr.stamina -= rand(4,7)
usr.maxpowerlevel += rand(50,250)
usr.maxki+= rand(1,5)
if(2)
usr.stamina -= rand(6,9)
usr.maxpowerlevel += rand(100,350)
usr.maxki+= rand(3,7)
if(3)
usr.stamina -= rand(2,5)
usr.maxpowerlevel += rand(25,100)
usr.maxki+= rand(2,8)
usr.will+=2
if(4)
usr.stamina -= rand(7,18)
usr.maxpowerlevel += rand(25,500)
usr.maxki+= rand(6,10)
usr << "<b><font size = 2>You get more will to fight."
usr.will+=3
if(5)
usr.stamina -= rand(1,3)
usr.maxpowerlevel += rand(15,60)
usr.maxki+= rand(4,9)
else
usr << "<FONT COLOR=White><b>You feel to tired.."