Data Realms Fan Forums
http://45.55.195.193/

How would I make part of a function update at a slower rate?
http://45.55.195.193/viewtopic.php?f=73&t=14877
Page 1 of 1

Author:  Erahgon [ Sat May 23, 2009 3:23 am ]
Post subject:  How would I make part of a function update at a slower rate?

Code:
function Create(self)

end

function Update(self)
      for actor in MovableMan.Actors do
         local diff = math.sqrt(math.pow((actor.Pos.X-self.Pos.X),2) + math.pow((actor.Pos.Y - self.Pos.Y),2))
         local ydiff = math.abs(actor.Pos.Y - self.Pos.Y)
         if ydiff < -30 then
            if not(actor.PresetName == "Dood") then
               actor.Vel.Y = 0
               
            end
            
         end
         if (diff < 100) and actor.PinStrength == 0 then
            if (ydiff < 100) then
               if not(actor.PresetName == "Dood) then
                  local diffx = actor.Pos.X - self.Pos.X
                  local diffy = actor.Pos.Y - self.Pos.Y
                  actor.Health = actor.Health -.2
               
                  local ang = math.atan2(diffy,diffx)
                  actor.Vel.Y =  -1
                  actor.Vel.X = 0
               end
            end
         end
      end
      

   
end
      

Code:
actor.Health = actor.Health -.2

Here's the line that I don't want updated every time the function updates. I tried using a counter but that didn't work properly for more than one actor.

Author:  mail2345 [ Sat May 23, 2009 4:09 am ]
Post subject:  Re: How would I make part of a function update at a slower rate?

For that, I would use a timer if you want non random, or try this:
Code:
actor.Health = actor.Health - math.floor(math.random(z)/z)


Set z higher to reduce rate.

Author:  Grif [ Sat May 23, 2009 6:13 am ]
Post subject:  Re: How would I make part of a function update at a slower rate?

Or the timer method:

in create event:

self.timer1 = Timer();


in update event:

if self.timer1:IsPastRealMS(3) then
do whatever
self.timer1:Reset();
end

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/