ID:2152689
 
(See the best response by Lummox JR.)
Code:
mob/Player/proc 
Hunger(mob/M)
M/var/HT = M.Hunger
if spawn(100) //I tried sleep(100) but it had errors
HT += 1
if (M.Hunger == 100)
usr << "You begin feeling weak from hunger."
M.Health -= 1
else if (M.Hunger == 50)
usr << "You feel hungry."
else return


Problem description:I'm trying to make it so every 100 ticks I become a little more hungry, and when my Hunger reaches 100% i start losing health and have to eat. This is the first proc I ever tried to do by myself.

Best response
Problems in this code:

- You don't need a mob/M argument for the Hunger() proc, because src is the mob it's working with; M is redundant.

- M/var/HT isn't correct syntax.

- The if statement needs parentheses, and if(spawn()) isn't valid. If what you're trying to do is call this proc just once to start a hunger loop going, this isn't the right way to go about it.

- HT is a local var, so the Hunger var itself is never actually changed.

- usr has no business in a proc.

- When you make the player lose health, you're not doing a death check.

I believe you need something more like this:

mob/Player/proc/Hunger()   // call this at login
spawn(-1)
while(!dead)
++Hunger
if(Hunger >= 100)
if(Hunger == 100) src << "You begin feeling weak from hunger."
--Health
// Normally, the killer is passed as an argument to a death check,
// but here there is no killer because it's hunger.
DeathCheck()
else if(Hunger == 50)
src << "You feel hungry.
sleep(100)