0
votes

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
2
well, this is not stock Lua. So, You need to provide more information. And it's not really clear what exactly are You trying to do and what kind of error are You getting.Kamiccolo
make yourself familiar with the while statement.Piglet
Just go through your code step by step and check what is going on. I dont know how exactly logitech mice work but i doubt they can do 1 nanosecond delays or how they process events if one script is already active. As far as i can see as long as you hold MB3 your script is working and slowly moving mouse down. Once you press MB1 it starts moving it 34 times faster for what appears to be 1 000 000 000 (milliseconds? ~ 300 hours) Or until it is released.IcedLance
@IcedLance where do you see nanosecond delays here?Piglet
I assumed until i=1000000000 represents the 0.5 sec delay, which would mean Sleep(1) is supposed to last half a nanosecond.IcedLance

2 Answers

2
votes

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.

0
votes

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