View unanswered posts | View active topics It is currently Sun Aug 25, 2019 3:10 pm



Reply to topic  [ 5 posts ] 
 Timer == ## 
Author Message
Data Realms SUPER Elite
Data Realms SUPER Elite

Joined: Thu Jun 03, 2010 10:06 pm
Posts: 3717
Location: Over there.
Reply with quote
Post Timer == ##
I have this timer, and I want it to do a function ONLY when it is equal to a random number. I only want this function to be done ONCE. I used IsPastSimMS, but that does the function every frame past the number.

How do I check if the timer is equal to a certain number?


Sat Jun 11, 2011 12:49 pm
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Timer == ##
There may be a better way of doing this, but my suggestion is the following:
Code:
function Create(self)
   self.MyTimer = Timer()
end

function Update(self)
   if self.MyTimer and self.MyTimer:IsPastSimMS(1234) then
      self.MyTimer = nil   -- delete the timer
      -- do stuff here
   end
end

A nil value always evaluate to false, so the "do stuff" code will only be accessed once.


Sat Jun 11, 2011 1:06 pm
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: Timer == ##
Method 1:
Quote:
SetSimTimeLimitMS
Sets the sim time limit value of this Timer, RELATVE to the start time. This is when the timer is supposed to show that it has 'expired' or reached whatever time limit it is supposed to keep track of.
LeftTillSimTimeLimitMS
Returns how much time in ms that there is left till this Timer reaches a certain time limit previously set by SetSimTimeLimitMS.

however, I donno how to use these function.

Method 2:
If timer:IsPastSimMS(N) and not timer:IsPastSimMS(N+1) then

Method 3:
Code:
local functiondone = 0
If IsPastSimMS(N) and functiondone == 0 then
blahblahblah
functiondone = 1;
end


I haven't validated these yet.

Edit:Abdul Alhazred's is much better.


Sat Jun 11, 2011 1:14 pm
Profile
Data Realms SUPER Elite
Data Realms SUPER Elite

Joined: Thu Jun 03, 2010 10:06 pm
Posts: 3717
Location: Over there.
Reply with quote
Post Re: Timer == ##
I thought about doing your second method, but I'm just really lazy. I had hoped there would be a function I didn't know about, but there ain't. I guess I'll do that.

I tried yours, Abdul, but didn't like the way it worked, seemed a little less stable. If there is any error AT ALL in this script, it will ruin everything.


Sat Jun 11, 2011 1:20 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11616
Location: Here
Reply with quote
Post Re: Timer == ##
Code:
function Create(self)
   self.randomTimer = Timer();
end

function Update(self)
   if self.ticked == nil and self.randomTimer:IsPastSimMS(1337) then
      self.ticked = true;

      (stuff)

   end
end


Sat Jun 11, 2011 8:51 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.018s | 15 Queries | GZIP : Off ]