'Lua error in simple code for logitech mouse

i am trying to make a script for logitech mouse that : when i aim on a game mouse 3 and press fire the mouse goes fast down for about 0.5 secs and the rest of the time until i release the firebutton 1 it goes slower down. code:

error in line 8(sleep(1))

function OnEvent(event, arg)
    if IsMouseButtonPressed(3)then
        repeat  
            if IsMouseButtonPressed(1) then
                i=1
                repeat
                    i= i + 1 
                    MoveMouseRelative(0,1)
                    Sleep(1)
                until i=1000000000 or (not IsMouseButtonPressed(1))
                if IsMouseButtonPressed(3)then
                    repeat
                        MoveMouseRelative(0,1)
                        Sleep(33)
                    until not IsMouseButtonPressed(1)
                end
            end             
        until not IsMouseButtonPressed(3)
    end
end




This works but not with the extra 0.5s faster responce in the start

function OnEvent(event, arg)

    if IsMouseButtonPressed(3)then
        repeat  
            if IsMouseButtonPressed(1) then
                repeat
                    MoveMouseRelative(0,1)
                    Sleep(33)
                until not IsMouseButtonPressed(1)
            end             
        until not IsMouseButtonPressed(3)
    end
end


Solution 1:[1]

error in line 8(sleep(1))

No, the error is in line 9 . This is a bug in LGS: for example, the error in the first line it would display as "line #0", etc.

i=1000000000

This is your actual error.
Replace it with i==1000000000.

In Lua the single = is used for assignments, and the double == is used for equality testing.

Solution 2:[2]

Just to add some additional information:

Instead of

if IsMouseButtonPressed(1) then
  repeat
    MoveMouseRelative(0,1)
    Sleep(33)
  until not IsMouseButtonPressed(1)
end

You can simply write

while IsMouseButtonPressed(1) do
  MoveMouseRelative(0,1)
  Sleep(33)
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Jones
Solution 2 Piglet