some questions about timer and trigger

Posted by Darmier on Mon 26 Sep 2016 12:32 PM — 10 posts, 37,038 views.

#0
Hi, I am a newbie.
I want to know:
1.How many times a trigger scanning in 1 second?
Or maybe I should ask what`s the refresh frequency of a
trigger?
2.Can we make a timer in lua?

3.I want to do: print"hello",wait(sleep,delay) 1 second,print"ok",wait 1 second,print" " ,wait,...... just like this.
who can help me programing in lua?

thank you all.
USA Global Moderator #1
Quote:
1.How many times a trigger scanning in 1 second?
Or maybe I should ask what`s the refresh frequency of a
trigger?

The what?

Quote:
2.Can we make a timer in lua?

https://www.mushclient.com/scripts/function.php?name=DoAfterSpecial

Quote:
3.I want to do: print"hello",wait(sleep,delay) 1 second,print"ok",wait 1 second,print" " ,wait,...... just like this.

https://www.mushclient.com/forum/?id=4956&reply=2#reply2
#2
Thank you.

1. I think there must be something always keep watch on a trigger, just like event. So I want to konw the refresh rate or refresh frequency or Hz or FPS.

2,3. I am a newbie, so I wish to do that in "pure" lua.

I hope that the maximum granularity of the timers is 0.01 seconds in the next version so I can make a small game in the window.
Australia Forum Administrator #3
See: http://www.gammon.com.au/scripts/doc.php?general=plugin_callbacks

In particular: OnPluginTick

This is designed to let you do something frequently (25 times a second). That would let you have a frame rate of 25.


Quote:

1.How many times a trigger scanning in 1 second?


Triggers are called when an incoming line arrives from the MUD. There is no particular "scan" time.
USA Global Moderator #4
Darmier said:
2,3. I am a newbie, so I wish to do that in "pure" lua.

As a newbie you should probably use the way suggested by someone who has many years of experience.

Nick Gammon said:
This is designed to let you do something frequently (25 times a second). That would let you have a frame rate of 25.
Optimistically. :)
Amended on Mon 26 Sep 2016 09:28 PM by Fiendish
Australia Forum Administrator #5
Yes, the advertised rate may not be met, as processing timers is a low priority.
#6
Nick Gammon said:

In particular: OnPluginTick

This is designed to let you do something frequently (25 times a second). That would let you have a frame rate of 25.


Thank you.That is so important and useful to me.

I try to use this function, I can start it, but I don't know how to stop and control it. So I need more help.
Australia Forum Administrator #7
You need to post some code if you want help with why it doesn't work.
#8

<script>
<![CDATA[
win="win"
WindowCreate(win,0,0,40,40,11,4,0xffffff)
WindowCircleOp (win, miniwin.circle_ellipse, 
                0, 0, 40, 40,                
                ColourNameToRGB("blue"), miniwin.pen_solid, 2, 
                ColourNameToRGB("cyan"), miniwin.brush_solid)
WindowShow(win,true)
x=0
y=GetInfo(280)-40
t=0
g=5
vx=5
vy=55
ty=0
z=3

function OnPluginTick( ... )
  WindowPosition(win,x,y,12,6)
  Redraw()    
  t=t+1
  ty=ty+1
  x=vx*t
  y=GetInfo(280)-40-vy*ty+0.5*g*ty*ty-z
  if y>=GetInfo(280)-40 then ty=0;vy=vy-z end
end
]]>
</script>


I use the code for simulating a ball jumping and jumping, but I don't konw how to stop the function OnPluginTick().

We can use "break" to stop "for" loop or "while" loop, and I want to konw if there is a command or method to stop the function.
Amended on Wed 28 Sep 2016 04:27 AM by Nick Gammon
Australia Forum Administrator #9
You are looking at this the wrong way around. If a function is designed to be called 25 times a second, you don't stop it doing that.

Look at it this way: If you want to walk the dog every day except Sunday, you don't somehow stop Sunday from coming around. You build in a test:


if today == "Sunday" then
  -- do nothing
else
  WalkTheDog ()
end -- if


So in your case if you don't want the ball to move then don't move it. Build a test into the function.