ID:149860
 
My code is there but its not working. What it should do is be a infinite loop, and restart itself every 36,000 cycles.
Also when i == 0, it should deducte 1 point from the hunger and thirst vars. Right now its just bottoming out with hunger being 0 & thirst being 0. Even if I eat and drink which should make my hunger and thirst var = 10, it doesn't change the hungerc or thirstc, so something is not right or its going so fast it reaching 0 too soon.

// Hunger/Thirst Check
mob/pc/New()
Timer()

mob/pc/proc/Timer()
var/i
for(i=36000, i<0, i--)
if (i == 0)
hunger -= 1
thirst -= 1
if (client.ckey == "LJR")
hunger = 10
thirst = 10
if (hunger < 0)
hunger = 0
if (thirst < 0)
thirst = 0
if (hunger > 5)
hungerc = "Full"
if (thirst > 5)
thirstc = "Full"
if (hunger < 6 && hunger > 0)
hungerc = "Hungry"
if (thirst < 6 && thirst > 0)
thirstc = "Thirsty"
if (hunger == 0)
hungerc = "Starving"
if (thirst == 0)
thirstc = "Dehydrated"

LJR</6></6></0></0></0>
[snip]
for(i=36000, i<0, i--)
[snip]

i starts out > 0 so the loop never starts. Also, from just the code you posted, I am not seeing how it is an infinite loop. Do you have something to call it when it is done?
In response to ACWraith

i starts out > 0 so the loop never starts. Also, from just the code you posted, I am not seeing how it is an infinite loop. Do you have something to call it when it is done?

nope not sure how to call it or where??

LJR
In response to LordJR
For updates such as you are attempting, I would first suggest Deadron's Event Loop (in the library section).

However, if you want to just make your own recursive loop, let Timer() call itself when it is done. Use spawn() right before you call it so that other things may happen while Timer() is busy. Something to the point of:

Timer()

// insert whatever your timer code is

spawn()
Timer()

Like I said though, Deadron's Event Loop should give you an easier way to accomplish your goal.

PS: Remember to fix the loop condition I mentioned (i>0) if you still use your loop.
In response to ACWraith
Still not working.. :(
In response to LordJR
you don't have anything in the loop to pause it, so it will go through the entire loop in a single tick. Place a sleep() in the loop to slow it down.

I'd recommend dumping the for() loop entirely and just spawn() off the next call as many ticks as you desire:

mob/pc/proc/Timer()
hunger -= 1
thirst -= 1
// all your if() statements go here
spawn(600) Timer() // Do it again in one minute.

In response to Shadowdarke
ok I'm giving this a whirl... but now I need to find a way to call it when the program starts. I know I need New() in there somewhere just not sure how to add it?

LJR

// Hunger/Thirst Check
mob/pc/Timer()

mob/pc/proc/Timer()
hunger -= 1
thirst -= 1
if (client.ckey == "LJR")
hunger = 10
thirst = 10
spawn(360) Timer()

I'd recommend dumping the for() loop entirely and just spawn() off the next call as many ticks as you desire:

mob/pc/proc/Timer()
hunger -= 1
thirst -= 1
// all your if() statements go here
spawn(600) Timer() // Do it again in one minute.

In response to LordJR
LordJR wrote:
ok I'm giving this a whirl... but now I need to find a way to call it when the program starts. I know I need New() in there somewhere just not sure how to add it?

world.New() will do the trick.
world
New()
// create timer and start it
...

Lummox JR
In response to Lummox JR
Try this..

World
New()
..()
spawn() Timer()
In response to Freeker
I got it working fine now thanks!! :)

Now I need to get this code working it doesn't speed up the character's movement when I change the movement_delay.

// Movement Control PC
mob/pc
var/tmp
next_move_time = 0
movement_delay = 3
Move()
if (world.time >= next_move_time)
next_move_time = world.time + 10
return ..() // Allows move
else
return 0 // Does not allow move

LJR
In response to LordJR
LordJR wrote:

The problem is here:
next_move_time = world.time + 10

It should be
next_move_time = world.time + <font color=#ffffa0>movement_delay</font>

Adjusting the movement_delay won't have any effect unless the movement delay is used in your proc.
In response to Shadowdarke
ah I got this from the FAQ, Deadron you might want to check this!

LJR
In response to Shadowdarke
What's the benefit of using spawn() over for() ?

proc/Timer()
for()
//lala
sleep(10)

proc/Timer2()
//lala
spawn(10) Timer2()
In response to Foomer
Foomer wrote:
What's the benefit of using spawn() over for() ?

proc/Timer()
for()
//lala
sleep(10)

proc/Timer2()
//lala
spawn(10) Timer2()

There isn't any benifit over the infinate for() loop you used there. The for() loop LordJR used terminates and that wasn't what he wanted, so I provided the first solution that came to mind.