Error <name> expected near "if"

lua
10,132

The function is missing a name. Lua reads to the next line looking for the function's name and gets confused when it finds an if statement.

Also, the first if statement should be if active == 0 then because == is the comparison operator.

Share:
10,132
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Hi this is my first lua code but I get a error pls fix it thx in advanced if you do get this working. I have a feeling its a small thing I'm missing.

    class 'Autochat'
    
    TalkTimer = Timer()
    local TalkDelay = 1 -- in minutes
    local active = 1
    
    function 
        if active = 0 then
            return
        end
    
        if active ~= "0" then
            if(TalkTimer:GetSeconds() > (60 * timeDelay)) then
                Chat:Broadcast("Hi the admin is offline.", Colors(0, 255, 0))
                TalkTimer:Restart()
            end
        end
    end
    Autochat = Autochat()
    
  • Oliver
    Oliver over 9 years
    also the if active ~= "0" should be if active ~= 0 since active is a number, and the timeDelay should probably be replaced by TalkDelay