lualogitech-gaming-software

Adding print to script


I've got a basic auto clicking script that I'd like to add a print function to that tells me the total sleep. I am incredibly new to LUA and what I've tried after reading a couple WIKIs hasn't worked. Everything I try I get "attempt to call a nil value".

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("capslock")then
if IsMouseButtonPressed(5)then
   repeat
   PressMouseButton(1)
   Sleep(math.random (51, 55))
   ReleaseMouseButton(1)
   Sleep (math.random(526, 530))
   until not IsMouseButtonPressed(5)
end
end
end

I'd like for each action to print to console the total sleep before it repeats. So for example it would output "577" if Sleep 51 and Sleep 526 were the math selections in the randomization. Is this possible?


Solution

  • You should use OutputLogMessage instead of print.
    You will see the output in the bottom window of LGS/GHUB Lua script editor.

    EnablePrimaryMouseButtonEvents(true);
    function OnEvent(event, arg)
     if IsKeyLockOn("capslock")then
      if IsMouseButtonPressed(5)then
       repeat
        PressMouseButton(1)
        local w1 = math.random (51, 55)
        Sleep(w1)
        ReleaseMouseButton(1)
        local w2 = math.random(526, 530)
        Sleep (w2)
        OutputLogMessage("Total sleep: "..tostring(w1+w2).."\n")
       until not IsMouseButtonPressed(5)
      end
     end
    end