title: game Lua scripting - using couroutine or polling?
body: <p>I am starting to learn how to use Lua scripting for different game profile with logitech software.</p>
  
  <p>First I tried to use onevent (I know it isn't very advanced) and created this attack combo script</p>
  
  <pre><code>function OnEvent(event, arg) 
      if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then --set flag for mb1
          mb1_pressed = true
      elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then --set flag for mb1=false
          mb1_pressed = false
      end
  end
  
  if mb1_pressed then --using flags to determine whether to start attack or not
      repeat
          presskey("A")
          Sleep(50)
          releasekey("A")
          Sleep(100)
          --if MB1 is release, it will also break script. if i only tap mb1, this will only execute the first line of attack without the rest below
          if not (**argument**, can be MB1/ismouse1) then break end
          presskey("S")
          Sleep(50)
          releasekey("")
          Sleep(120)
          presskey("A")
          Sleep(50)
          releasekey("A")
          Sleep(200)
          if not (**argument**, can be MB1/ismouse1) then break end --if MB1 is release, it will also break script. this point will prevent script from looping from start if mb1 release
      until not (**argument**, i use ismouse1) --end the loop of script
  end
  </code></pre>
  
  <p>So I am trying to bind this to G6 button of my logiech mouse (using mouse_button_press == 6)
  Setting a flag with MB6 works, but ending a loop/breaking a loop cannot be triggered by MB6</p>
  
  <p>After some research on SDK/Lua forum of logitech support, it seems that there is a problem with my script</p>
  
  <ol>
  <li>Flags cannot be used/detect as an <strong>argument</strong> while a script is performing a loop sequence</li>
  <li>IsMouseButtonPressed (reads windows keypress) can be used in place or arguments</li>
  <li>Windows only detects MB1-5, so binding to G6 is not possible (registers as 6th button)</li>
  </ol>
  
  <p>I read that using couroutine.yield() or polling can be used for stopping repeat scripts in loop. But I cannot find a tutorial for beginners online.</p>
  
  <p>Sorry for the noobish question!</p>