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.
[code]
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.\nYou will be unable to use gForum until your connect to the database.\n") 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 )
[/code]
instead of
[code]
if !database.connected then return MsgC(Color(255, 0, 0), "Warning the Login System isn't connected to the database.\nYou will be unable to use gForum until your connect to the database.\n") end
[/code]
do the MsgC first, and then return end.
[QUOTE=whitestar;48390625]instead of
[code]
if !database.connected then return MsgC(Color(255, 0, 0), "Warning the Login System isn't connected to the database.\nYou will be unable to use gForum until your connect to the database.\n") end
[/code]
do the MsgC first, and then return end.[/QUOTE]
the ConnectToSql function works fine, the timer is my problem
[QUOTE=whitestar;48390625]instead of
[code]
if !database.connected then return MsgC(Color(255, 0, 0), "Warning the Login System isn't connected to the database.\nYou will be unable to use gForum until your connect to the database.\n") end
[/code]
do the MsgC first, and then return end.[/QUOTE]
I think he was talking about this [QUOTE=AutoJuke;48390494]
[code]
timer.Simple( 950, Reconnect )
[/code][/QUOTE]
[editline] [/editline]
Ninja'd :v:
[QUOTE=JasonMan34;48390677]-snip-[/QUOTE]
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 [URL="http://wiki.garrysmod.com/page/timer/Create"]timer.Create[/URL]
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)
Sorry, you need to Log In to post a reply to this thread.