View Full Version : Simple Question about Lua

October 3rd, 2007, 04:54 PM
I am a beginner in Girder-lua, and I need to write a simple script to
trigger an event periodically, Just want know two things that I found really hard to understand in the Help document.

1. gir.TriggerEventEx([eventstring], [eventdevice], [keymodifier],[payload] ... )
where can I find the eventdevice? If I want to trigger a keystroke of "a", what device number should this event belongs to?

2. [Timer] = gir.CreateTimer([arm], [trigger], [cancel], [recurring],[childstate])
If I want to, for example, to active an event once 5 sec, can I say


--trigger the event
t = gir.CreateTimer("", "", true, true)


In fact I find this code does not set up a timer as I wanted, but I
would hardly figure out the problem.
It will be very helpful if someone could help me with those problems,
thanks a lot.

October 3rd, 2007, 05:05 PM
There are a few ways to handle this. Could you describe the action to be taken when your event occurs?

October 3rd, 2007, 06:24 PM
1. The easiest way to find the eventdevice numbers is to go to Settings>Plugins and when you select the various plugins it shows the deviceid's (I think its the same as the event device but don't quote me on that). On the rest of it I'm not sure as I'm learning Lua too.


local eventFunction = function()

--Trigger your event


t = gir.CreateTimer("", eventFunction, "", true, true)

Put that into a file called something like "triggerevent.lua" and stick it in the "Girder5\luascript\startup" and it will trigger your event every 5 seconds. That much I do know because I have something similar to grab song title info from my xbox media center every 5 seconds.

October 4th, 2007, 09:27 AM
Yesterday i found a problem in posting thread, so did not reply in time.

The problem is the keystroke will show up one by one without a break, that means the timer is not working.

Yes, your code is working! and give me a better understanding of the function. Thanks.

October 4th, 2007, 10:32 AM
Yes, your code is working! and give me a better understanding of the function. Thanks.

You're welcome. I've asked more than my fair share of questions here so if I can help people I do.

One note.. do not make your timer a local as they work only up until the first garbage collection which is when they die because Girder doesn't think they are being used.


local t = gir.CreateTimer("", eventFunction, "", true, true)
... looks the same but will only work for a short time. Just thought you should know.

October 5th, 2007, 11:31 AM
Get another problem :confused:

I want to stop the recursive action by using <F11> to reboot the engine (because i can not find other ways to do it except for closing Girder). And i try to use an script action as

gir.TriggerEventEx("7A000000", 202, 0)

To send a <F11> to Girder. When i hit the <F11> directly, the action stops but the script action did not work, the <F11> was sent but the action was remain running. Just wonder why? and if there are other ways to stop a running action? Thanks.