View unanswered posts | View active topics It is currently Thu Dec 26, 2024 4:51 am



Reply to topic  [ 3 posts ] 
 How would I make part of a function update at a slower rate? 
Author Message

Joined: Thu Apr 12, 2007 2:53 am
Posts: 83
Reply with quote
Post 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.


Sat May 23, 2009 3:23 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Sat May 23, 2009 4:09 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Sat May 23, 2009 6:13 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.058s | 13 Queries | GZIP : Off ]