Timed chat messasge not working? HELP!

Hi,

I’v been writing a lua file and I’m not sure why this code isn’t working.


 if i == 1 then
	function ChatWarning()
		timer.Create("ChatWarning", 30, 0, function()
			PrintMessage(HUD_PRINTTALK, "Maintenance mode: On
 The server may become unstable or close unexpectedly!")
		end)
	end
end 

I’m trying to make the message print to the chat every 30 seconds if the variable i = 1

Yes, I have already set the variable.

is [lua]if i == 1 then[/lua] embedded in a function?

And whats i set to?

Create the function outside if the if statement. Also, “i” is a bad variable to use, and use true/false, not numbers.



function ChatWarning()
    timer.Create( "ChatWarning", 30, 0, function()
         PrintMessage(HUD_PRINTTALK, "Maintenance mode: On
 The server may become unstable or close unexpectedly!")
    end )
end

if maintenanceMode == true then
     ChatWarning()
end


No it isn’t embedded in a function. i is set to 1.


          -- Enabled code here
		RunConsoleCommand("hostname", hostname_maintenance)
		PrintMessage(HUD_PRINTTALK, "Maintenance mode: On")
		i = 1


[editline]18th December 2016[/editline]

Ok, I’ll give it a try, thanks!