timer.Simple Not Working?

So i was setting up GForum and noticed that it disconnects a lot so i tried timer.Simple to make it run the ConnectToSQL() Function every few minutes and didn’t seem to work.

In Fact the timer doesn’t run at all, It only reconnects with the ls_reconnect command.

I haven’t noticed any lua errors so i’m not sure what the problem is.

Thanks.



function ConnectToSQL()
	require("mysqloo")
	
	database = mysqloo.connect(Host, User, Pass, DB, Port)
	
	database.onConnected = function()
		database.connected = true
		print("Successfully to connected to database.")
	end
	
	database.onConnectionFailed = function()
		database.connected = false
		print("Failed to connect to the database.")
	end
	
	database:connect()
	
	timer.Simple(3, function()
		if !database.connected then return MsgC(Color(255, 0, 0), "Warning the Login System isn't connected to the database.
You will be unable to use gForum until your connect to the database.
") end
		local query1 = database:query( "CREATE TABLE IF NOT EXISTS " .. Prefix .. "_link (`id` INTEGER NOT NULL, `steamid` TEXT NOT NULL)")
		query1:start()
		
		local query2 = database:query( "CREATE TABLE IF NOT EXISTS " .. Prefix .. "_rank (`id` INTEGER NOT NULL, `rank` TEXT NOT NULL, `steamid` TEXT NOT NULL)")
		query2:start()
	end)
end
concommand.Add("ls_reconnect", ConnectToSQL )


function Reconnect()
	ConnectToSQL()

	if !database.connected then print("Login System Re-Connected")
	end
end

timer.Simple( 950, Reconnect )


instead of



if !database.connected then return MsgC(Color(255, 0, 0), "Warning the Login System isn't connected to the database.
You will be unable to use gForum until your connect to the database.
") end


do the MsgC first, and then return end.

the ConnectToSql function works fine, the timer is my problem

I think he was talking about this

[editline] [/editline]

Ninja’d :v:

No he doesnt want to run the reconnect function in the timer, he wants to run other stuff, but the timer doesnt seem to be working somehow.

First of all timer.Simple will only call the function once, if you want to happen forver use timer.Create
Also, why are you defining a function that runs a different function? Seems a bit useless if all it adds is a notification…

iirc timers won’t work on the server unless the server is active (i.e has a player or a bot on)