-1

i have been learning lua to code an auto clicker for my g903 that works when the right mouse button is held and can be toggled with the capslock key. any help or insight would be appreciated

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event,arg)=true
    if IsKeyLockOn("capslock"=true then
        if IsMouseButtonPressed(3)=true then
            repeat
                if IsMouseButtonPressed(1)=true then
                    repeat
                        PressAndReleaseMouseButton(1)
                        Sleep(math.random(20,80))
                    until IsMouseButtonPressed(1)=false
                end
            until IsMouseButtonPressed(3)=false
        end
    end
end

1 Answers1

2

function OnEvent(event,arg) is the beginning of a function definition. You cannot assing true here as attempted in function OnEvent(event,arg)=true. This will give an error for an unexpected symbol near '='. Lua cannot make sense of this.

In if IsKeyLockOn("capslock"=true then you're missing a cosing parenthesis. After adding that it is still incorrect as for all the following lines:

if IsKeyLockOn("capslock")=true then
if IsMouseButtonPressed(3)=true then
if IsMouseButtonPressed(1)=true then

you get an error 'then' exepected near '='

until IsMouseButtonPressed(1)=false
until IsMouseButtonPressed(3)=false

you get an error '' expected near 'until'

You are confusing the assignment operator = with the equality operator ==.

See Relational Operators and Assignment

As a side note, these functions are already returning true or false.

You don't have to explicitly check wether the return value equals true. There are only two possible outcomes. true == true -> true or false == true -> false. So you can use the return value directly and simply write if IsMouseButtonPressed(1) then.

If you want to do someting in the false case it is common practice to simply negate the return value. not false -> true

In this case you simply write if not if not IsMouseButtonPressed(1) then instead of if IsMouseButtonPressed(1) == false then.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • In addition, `IsMouseButtonPressed` etc return a boolean. Comparing a boolean with `true` effectively does nothing, so you can remove all `== true`. Similar with `== false`, it's more common to use [`not`](https://www.lua.org/pil/3.3.html) instead. – Luke100000 Oct 14 '21 at 07:47
  • ive fixed the code as you suggested and it shows no errors now and seems to "work" according to ghub but the script still isnt registering clicks. – Bush Kangarutha Oct 15 '21 at 05:48
  • CURRENT CODE IS AS FOLLOWS; `EnablePrimaryMouseButtonEvents(true); function OnEvent(event,arg) if IsKeyLockOn("capslock") then if IsMouseButtonPressed(3) then repeat if IsMouseButtonPressed(1) then repeat PressAndReleaseMouseButton(1) Sleep(math.random(20,80)) until not IsMouseButtonPressed(1) end until not IsMouseButtonPressed(3) end end end` – Bush Kangarutha Oct 15 '21 at 05:49
  • please ask a new question – Piglet Oct 15 '21 at 06:35