PDA

View Full Version : Lua skipt for checking routine doesn't work



Pinkie2
January 7th, 2013, 07:15 AM
Dear Lua experts

I'm quite new to scripting in LUA so please be lenient...
I've copied together this little routine from the forum. It should one day end up in a security solution. After a lua engine reset it works fine but after I ran it the first time I get the voice message when I hit the event "test" (when the timer is supposed to be ended) multiple times (mostly three times). WHY?!
do you have an idea?
Thanks


-- Messages
vm1 = function ()
Voice:Speak("please check")
end

vm2 = function ()
Voice:Speak("warning")
end

-- Set Timer
function Timer (s, e, d, l, x) --START, END, DURATION, LOOP (0/1), EXIT?
if x == 0 then
gir.TriggerEvent("WMP.vol50", 1); -- Sets Volume
t = gir.CreateTimer(s, e , "", l)
t:Arm(d)
else
Voice:Speak("check")
t:Destroy(); t = nil;
end
end


-- Exit Timer
gir.AddEventHandler('test', 1, 9999,
function ()
gir.TriggerEvent("WMP.vol50", 1) -- Sets Volume
Timer (0, 0, 0, 0, 1)
end)

--Check Process starts
Timer (vm1, vm2, 3000, 1, 0)

Tieske8
January 8th, 2013, 03:16 PM
You're describing what the code doesn't do, but what is it that you want the code to do?

At least the code looks like it could be simplified, but that depends on what you want it to do.