ID:149362
 
Ok, I want it to take from health and happiness every 60 ticks, but the code only does it once. I'm not sure what to do.

New()
usr.Move(locate(5,6,1))
. = ..()
spawn()
healthdown()

proc/healthdown()
if(health) spawn(60) health -= 5
if(happy) spawn(60) happy -= 5
return
Likwiddraino000 wrote:
Ok, I want it to take from health and happiness every 60 ticks, but the code only does it once. I'm not sure what to do.

New()
usr.Move(locate(5,6,1))
. = ..()
spawn()
healthdown() <font color=#ffffa0>// extra tab here</font>

proc/healthdown()
health = max(0,health - 5) // if health-5 is less than 0, then health will be 0
happy = max(0,happy - 5)
spawn(60) // in 6 seconds
healthdown() // do this proc again
Likwiddraino000 wrote:
Ok, I want it to take from health and happiness every 60 ticks, but the code only does it once. I'm not sure what to do.

New()
usr.Move(locate(5,6,1))
. = ..()
spawn()
healthdown()

proc/healthdown()
if(health) spawn(60) health -= 5
if(happy) spawn(60) happy -= 5
return

Huge problems in your code, here.

  • You've got usr in New(). What the heck were you thinking? You should avoid it outside of verbs unless you're absolutely positive you're using it correctly.
  • Calling Move() before ..() isn't going to do you a whole lot of good in New(), and if this is a player mob you should be calling it in the Login() proc.
  • healthdown() isn't indented under spawn(), so it's not being spawned out. DM thinks you're telling it to spawn nothing.
  • As soon as healthdown() runs, it spawns off two separate lines of code and then immediately returns; it never respawns itself.
  • The ifs you have should occur after the spawn, when the subtraction code is run; otherwise, if something else decrements health or happy in the meantime, you could get into negative numbers.
  • Subtracting 5 from either var will give you negative numbers if you don't have an exact multiple of 5. What you probably want instead are lines like happy=max(happy-5,0), in which case you can also eliminate the ifs.

    Your code should look like this instead:
New()  
..()
spawn(60) healthdown()

proc/healthdown()
health=max(health-5,health)
happy=max(happy-5,happy)
spawn(60) healthdown()

Lummox JR
In response to Shadowdarke
I put the code in there but it never takes health or happiness from the player.

New() //This is called when the atom enters the world
..()
spawn(60)
healthdown()

proc/healthdown()
health=max(health-5,health)
happy=max(happy-5,happy)
spawn(60)
healthdown()
In response to Likwiddraino000
Likwiddraino000 wrote:
I put the code in there but it never takes health or happiness from the player.
[snip]
proc/healthdown()
health=max(health-5,health)
happy=max(happy-5,happy)
spawn(60)
healthdown()

You botched both calls to max(). Shadowdarke and I both showed you the same code (I guess we posted more or less simultaneously) but with a different order to the arguments.

Instead of pointing you back to our code right away, I'm gonna give you another look at what you did here so I can say "DUH!"

health=max(health-5,health)
happy=max(happy-5,happy)

max() returns the bigger of two values. Which is bigger, health or health-5?

DUH!

Now back to our code. Shadowdarke and I both put this instead (except Shadowdarke put the 0 first):

health=max(health-5,0)
happy=max(happy-5,0)

Slightly different, isn't it? This says to use health-5 for the new health value, unless it's less than 0--then 0 is greater, and it's used instead.

Lummox JR