PDA

View Full Version : Simple Question about Lua



PengLi
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])
[Timer]:Arm([timeout])
If I want to, for example, to active an event once 5 sec, can I say

while(1)

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

End

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.

harleydude
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?

NeoMorph
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.

2.

local eventFunction = function()

--Trigger your event

end

t = gir.CreateTimer("", eventFunction, "", true, true)
t:Arm(5000)


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.

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

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

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

NeoMorph
October 4th, 2007, 10:32 AM
NeoMorph:
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.

So....

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

PengLi
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.