Lua LGS Scripting loop not ending

Multi tool use
Lua LGS Scripting loop not ending
I am trying to write a simple loop to click on intervals until I push the button again. I do not know why this code is not working. The loop will initiate, but nothing I've tried so far can properly end the loop once it begins. This is my code.
function OnEvent(event, arg, family)
OutputLogMessage("event = %s, arg = %dn", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
Active = 0
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2)
end
function Ire()
PressAndReleaseMouseButton(1)
Sleep (1000)
end
if (event == 'G_PRESSED' and arg == 16 and Active == 0) then
Active = 1
SetBacklightColor(255, 0, 0, "kb")
elseif (event == 'G_PRESSED' and arg == 16 and Active == 1) then
SetBacklightColor(110, 255, 90, "kb")
Active = 0
end
while Active == 1 do
Ire()
end
end
while Active == 1 do Ire() end
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
This loop blocks the execution:
while Active == 1 do Ire() end
. Event handler must exit QUICKLY. Read about "event-driven programming" to understand the principle.– Egor Skriptunoff
Jul 3 at 7:08