LUA scripting switching on/off a script
<p>I'm writing a script in LUA/logitech scripting API. The script should perform the following: <br>  <li>mouse key 4 switch on/off the script</li><li>mouse key 5 switch from one feature to other ( force move and autoattack )
<br><br>The code is the follow:</p>

<pre><code>forceMove = false
on = false
function OnEvent(event, arg)
    --OutputLogMessage("event = %s, arg = %s\n", event, arg);
    if IsMouseButtonPressed(5) then
        forceMove = not forceMove
        while(on) do
            if(forceMove) then
                ForceMove()
            else
                StartAttack()
            end
        end
    ReleaseMouseButton(5)
    end

    if IsMouseButtonPressed(4) then
        on = not on
        ReleaseMouseButton(4)
    end
end

function StartAttack()
    PressAndReleaseMouseButton(1)
    Sleep(1000)
end

function ForceMove()
    MoveMouseWheel(1)
    Sleep(20)
    MoveMouseWheel(-1)
end
</code></pre>

<p>but once in game,if i activate the script with mouse button 4, i get stuck in "force move" mode, and "auto attack" mode never works. Can't figure why.</p>