ID:1563479
 
(See the best response by MisterPerson.)
Code:
obj/Decoration
icon='InteriorDeco.dmi'
Bed1
icon_state="bed1"
density = 1
Bed2
icon_state="bed2"
Entered(mob/M)
M.bedresting=1
Exited(mob/M)
M.bedresting=0
Bench
icon_state="Bench"
Entered(mob/M)
M.benchresting=1
Exited(mob/M)
M.benchresting=0
Bed3
icon_state="bed3"
density = 1
Bed4
icon_state="bed4"
Entered(mob/M)
M.bedresting=1
Exited(mob/M)
M.bedresting=0

mob/proc
meditate()
if(usr.resting)
usr.MaxPower += (1 *0.0030)
usr.Exp += (1 *0.0015)
spawn(100)
usr.meditate()
if(usr.bedresting==1)
usr.Exp += (1 *0.0015)
usr.icon_state="Focus"
usr.bedrest()
if(usr.benchresting==1)
usr.icon_state="KO"
usr.benchrest()
if(usr.Power > usr.MaxPower)
usr.Power = usr.MaxPower
usr.meditate()


Problem description: Alright so I am trying to make it so that when you walk up to a bed, jump in it, and hit meditate you automatically begin to go through a rest proc, different from the normal meditation. However. In game when you go up to the bed and lay in it it does not toggle the 'bedresting' var to one like I have it set, same with benchresting. I can not figure out what is going on at -all- and was wondering if someone could help me

You need to call meditate() after setting bedresting/benchresting. By default, simply defining a procedure doesn't make it an event listener (it doesn't do anything regardless of something else's state, such as what you're attempting). You could set it up to do so by having meditate() silently loop without doing anything until those variables change, but that might be a bit overkill.

There are a few other issues with your meditate() procedure however. In a procedure, you should not be using usr (as there will be some scoping confusion in certain circumstances). You're better off using src there.

Secondly, meditate() is an infinite recursion error waiting to happen. The spawn statement is meant to start a new block—much like an if statement. The way you have it now however, spawn (100) will do... nothing and it will immediately call usr.meditate() in meditate(), resulting most likely in a crash.
Best response
You need to use Crossed() and Uncrossed() instead of Entered() and Exited(). Entered/Exited is for physically being inside the object while Crossed/Uncrossed are for walking onto the same turf as the object.
Thank you that helped a lot. HOWEVER now I am dealing with something new. I moved the orginal stuff to the actual meditate verb instead of a proc inside the verb... Now when I hit meditate there is a 5 second delay while on a bed/bench. I am so confused on what is going on...


mob/verb
Meditate()
set category = "Combat"
if(usr.Null)
return
if(usr.KO)
return
if(!usr.resting&&usr.move&&usr.allowmed&&!usr.bedresting&&!usr.benchresting)
usr.meditate=1
usr.icon_state="Focus"
usr.move=0
src.rest()
src.meditate()
if(usr.bedresting==1)
usr.Exp += (1 *0.0015)
src.bedrest()
if(usr.benchresting==1)
usr.icon_state="KO"
src.benchrest()
usr.resting=1
else
usr.resting=0
usr.icon_state=""
usr.move=1
usr.meditate=0
usr.allowmed=0
sleep(50)
usr.allowmed=1


That is the code. MIND HELPING A BROTHA ONE MORE TIME?
sleep(50)
No no. I mean there is a 5 second delay before it actually switches to bed resting and bench resting. The sleep fifty is after you already are meditated and hit it again.
What does bedrest() do?
It does this.
mob/proc
bedrest()
if(usr.bedresting&&!usr.meditate)
if(usr.Power < usr.MaxPower)
usr.Power += (usr.RegenPower*4.2)
if(usr.Power > usr.MaxPower)
usr.Power = usr.MaxPower

if(usr.Stamina < usr.MaxStamina)
usr.Stamina += (usr.MaxStamina/20)
if(usr.Stamina > usr.MaxStamina)
usr.Stamina = usr.MaxStamina


if(usr.Health < usr.MaxHealth)
usr.Health += (usr.RegenHealth*2)
if(usr.Health > usr.MaxHealth)
usr.Health = usr.MaxHealth

if(usr.Strength < usr.MaxStrength)
usr.Strength += (usr.MaxStrength/20)
if(usr.Strength > usr.MaxStrength)
usr.Strength = usr.MaxStrength

if(usr.Agility < usr.MaxAgility)
usr.Agility += (usr.MaxAgility/20)
if(usr.Agility > usr.MaxAgility)
usr.Agility = usr.MaxAgility


if(usr.Offence < usr.MaxOffence)
usr.Offence += (usr.MaxOffence/20)
if(usr.Offence > usr.MaxOffence)
usr.Offence = usr.MaxOffence

if(usr.Defence < usr.MaxDefence)
usr.Defence += (usr.MaxDefence/20)
if(usr.Defence > usr.MaxDefence)
usr.Defence = usr.MaxDefence
Not sure I understand your problem fully. What do you mean by "bed resting switch to bench resting"?
what I mean is that the icon state and general meditation isn't switching right away only while in a bed or on a bench until 5 seconds after hitting the meditation verb but off a bed/bench it activates right away.
Or longer even.
Post the code for rest().
Nvm I figured it out thanks for all your help guys~