General > Developers Corner

Lua Timers.

(1/2) > >>

LuaTenshi:
[link]

 ::) Thats my code.

No matter what I do I cant seem to get the timers working, I have used simple timers, but as soon as they run out they just keep executing the command without waiting ever again.

The Timers that I have there do not return any errors to the server, they just don't work. Every thing works fine except the timers. Please help?

I would like this answered ASAP.

JamminR:
I'm not sure of any below point which might break timers. My experience with them is limited.
-You're using think functions to run the timer every frame (barring if statements)
-You're running the stop function within the timer. (Perhaps it doesn't work well this way)
-You're running the timer forever (0 reps = forever) (Why use timer rep forever AND in think statement running it every frame (barring if boolean)).
-Though the old timer.create example shows using the function() statement within a timer.create, perhaps due to locality of function, its not grabbing variables within it?
- ... all i can think of for now

Megiddo:
I believe you're resetting the timer every frame since you're creating it inside a think function.

JamminR:

--- Quote from: JamminR on May 13, 2012, 08:42:04 PM ----You're using think functions to run the timer every frame (barring if statements)

--- End quote ---

- You're resetting the timer every frame (Like Megiddo said)

There, fixed my original point. :P

LuaTenshi:
Yea, I realized that so I fixed it and now it works.

I have been able to pin point where the lag is coming from...


--- Code: ---timer.Create( "WaterExtinguish", 0.5, 0, function()
    for _, ent in ipairs( ents.GetAll() ) do
        if ( ent:IsValid() and ent:IsOnFire() and ent:WaterLevel() > 0 ) then
            ent:Extinguish()
        end
    end
end)

--- End code ---

Oh and don't worry its not connected to the think hook. :P

Navigation

[0] Message Index

[#] Next page

Go to full version