[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Countdown Timer

Countdown Timer

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Rene   (46 posts)  [Biography] bio
Date Sat 09 Dec 2017 10:32 PM (UTC)
Message
Hello, I want my colour trigger to have a countdown timer so it does go off too many times in a row, say a 5 second wait.

The line to play the sound is:

PlaySound (0, IsSound, false, 0, 0)

I assume I want some kind of for statement beforehand with a timer, but I don't know where to start.
Thanks!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 10 Dec 2017 12:04 AM (UTC)
Message
You can use the Lua function os.time to find the current time in seconds.

What I would do is store that in a global variable, in your trigger, if the variable is not already set. Something like this:


<triggers>
  <trigger
   enabled="y"
   match="foo"
   send_to="12"
   sequence="100"
  >
  <send>

-- if 10 seconds are up forget about when it last fired and zero the counter
if recentTimeTriggerFired then
  if os.difftime (os.time (), recentTimeTriggerFired) &gt;= 10 then
    timesTriggerNoticed = 0
  end -- if over 10 seconds since last time

  -- IF less than 5 seconds have elapsed
  -- AND it has fired more than 3 times
  -- THEN play the sound

  if os.difftime (os.time (), recentTimeTriggerFired) &lt;= 5 and
     timesTriggerNoticed &gt;= 3 then
     check (PlaySound (0, "tada.wav"))
     timesTriggerNoticed = 0
  end -- end of 3 times in a row with the most recent less than 5 seconds ago
end -- if it fired before

recentTimeTriggerFired = os.time ()
timesTriggerNoticed = (timesTriggerNoticed or 0) + 1

</send>
  </trigger>
</triggers>




Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


8,895 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]