ID:144342
 
Code:
mob/proc/staminacheck()
if(src.stamina>=100)
src.stamina=100
if(src.stamina<=0)
src.stamina=0
mob/proc/rest()
src.staminacheck()
if(src.canmove)
src<<"<font color=green><b>You begin resting!</font></b>"
src.canmove=0
if(src.stamina<100)
sleep(15)
src.stamina+=rand(1,5)
src.HP+=rand(1,5)
src.hpmpcheck()
src.Healthbars()
src.rest()
else
src<<"<font color=red><b>Your stamina is full!</b></font>"
src.staminacheck()
src.canmove=1
else
if(src.stamina<100)
sleep(15)
src.stamina+=rand(1,5)
src.HP+=rand(1,5)
src.hpmpcheck()
src.Healthbars()
src.rest()
else
src<<"<font color=red><b>Resting Complete!</font></b>"
src.staminacheck()
src.canmove=1

obj
hud
restbutton
icon='misc.dmi'
icon_state="rest"
name="Rest"
New(client/C)
screen_loc="4,1"
C.screen+=src
layer=MOB_LAYER+5
Click()
usr.rest()


Problem description:
The code as it is now works fine. But I want to the above code to stop resting if the user presses the restbutton(or verb) again during resting, but continue if the user's stamina is under 100 and does not press the restbutton(or verb) a second time during resting. I cant figure out how to do this.
You would use a var to check if they are resting. When its false (before they rest) make it true. When they click it and its true (during resting), make it false. When restoring stamina in the proc, check for this variable. If its false, return.
In response to Pyro_dragons
Pyro_dragons wrote:
You would use a var to check if they are resting. When its false (before they rest) make it true. When they click it and its true (during resting), make it false. When restoring stamina in the proc, check for this variable. If its false, return.

I've done kinda what you said above before, but not exactly. When I did that it would not loop and continue the resting process. If you know of a way please edit the code above I've posted and show me.
In response to FriesOfDoom
FriesOfDoom wrote:
I've done kinda what you said above before, but not exactly. When I did that it would not loop and continue the resting process.

..because you did it incorrectly.

If you know of a way please edit the code above I've posted and show me.

No. We will tell you HOW to code stuff, possibly giving code examples, however you're the one who will code his own game. If we just give you code away, you wouldn't learn from coding it, and wouldn't know how to do things in the future.
In response to Kaioken
Kaioken wrote:
FriesOfDoom wrote:
I've done kinda what you said above before, but not exactly. When I did that it would not loop and continue the resting process.

..because you did it incorrectly.
No really? I thought my computer was just mad at me >_>
If you know of a way please edit the code above I've posted and show me.

No. We will tell you HOW to code stuff, possibly giving code examples, however you're the one who will code his own game. If we just give you code away, you wouldn't learn from coding it, and wouldn't know how to do things in the future.

_> I know how to put it in, I just cant think of where to put it.I've tried many spots,but they all end up breaking the loop.I'm asking where I need to put it, not how to do it. Besides telling me where to put a "rest=1","rest=0",and "if(!src.rest)" in my own code isnt really giveing me code, specially since I made and posted all of my proc code above. If telling me where I should put 3 lines of code to improve a proc I coded(and it works fine as it is) isnt coding my own game, my name is Opera. No wonder there's so many rips, someone new asks a question even on placement and you people who know how to code well jump all over his/her ass.
In response to FriesOfDoom
anyone else want to actually help me?
In response to FriesOfDoom
Note: This may not work, I'm going off the top of my head.

Try doing this at the beginning of the rest button

var/prematurestop = false //This should be a mob var, not in the rest button

//in the rest button
Click()
if(prematurestop == false && stamina < 100)
prematurestop = true
else if(prematurestop == true)
//stop stuff
prematurestop = false
else
//stop stuff


//the else is there for if stamina is already 100.

Please Read my note before assuming this will instantly work.

Like always, this isn't perfectly done, and it's not built to be smacked into your code.

~Polantaris
In response to Polantaris
Thank you very much, this helps quite a bit! Good thing there's early release tommarrow, I'll mess around with my rest proc and see if I can figure out what I need to change with help from the example you gave.

Words+person new to coding= 0.1% help,
Example of some kind+words+person new to coding=85% help,
Example+words+person new to coding+learns by pictures=95% help(me) :P
In response to FriesOfDoom
Glad to be of help.
If you need more specific help, feel free to email me ([email protected]) and I'll try to help (but not do for you of course =P)

~Polantaris