Search code examples
lualogitech

Lua Scripting for G13 Syntax Error on While Loop


I'm trying to put together an autofishing script for Terraria that will do more than just click at scheduled intervals. At this point, it's giving me a syntax error at the line that says while fishing do.

I've tried separating the while and the do to different lines, putting the fishing into parentheses, putting something else between the line before and the while loop in case it's the line before actually causing the problem. The only thing that any of any of those accomplished was when I put the do on the next line. When I did that it complained about the line with just do.

I'm pretty new to Lua scripting, but it looks like the exact same sort of while loop as I've seen in the documentation.

fishing = false

function goFish()
    PressAndReleaseKey("d")
    Sleep(5)
    PressAndReleaseKey("d")
    PressAndReleaseKey("1")
    local x = GetRunningTime()
    while fishing do
        if(GetRunningTime() % 180000) == 0) then PressAndReleaseKey("b") end
        PressAndReleaseMouseButton(1)
        Sleep(4500)
        if(GetRunningTime()-x > 6000000) then
            x = getBait()
        end
    end
end

Solution

  • The error is at this line:

    if(GetRunningTime() % 180000) == 0) then PressAndReleaseKey("b") end
    

    which should be

    if(GetRunningTime() % 180000) == 0 then PressAndReleaseKey("b") end
    

    or

    if((GetRunningTime() % 180000) == 0) then PressAndReleaseKey("b") end
    

    In Lua IF conditions do not need to be wrapped in parentheses.