Okay, most of it is solved now. I have one little thing left I guess.
I'm using two .lua files. One file is called something_mysql.lua and something_sqlite.lua, both having the same database-function-names for the main karmabet function which are only being defined if "mysql" or "not mysql" is chosen. Basically just wrappers for the "save"-function of the main logic.
Both have the hook.Add() construct as you told me before to determine which one to load depending on the settings. We've also seen that print() seems to be printing out information even though the server has not ticked, yet (which is very strange honestly).
The sqlite scripts starts like this:
local i = 1
local function loadSQLite( force )
-- This function runs when the server is fully loaded
-- All cvars have been read and are available within this function
hook.Remove( "Think", "karmabet_sqlite_think" ) -- Only run this callback once
-- We can now make sure save mode has been set to "sqlite"
if not force and string.lower( GetConVar( "karmabet_savemode" ):GetString() ) == "mysql" then
return -- Stop! Save mode is not sqlite...
end
-- We fall back to SQLite if the savemode was messed up
if not force and string.lower( GetConVar( "karmabet_savemode" ):GetString() ) ~= "sqlite" then
print("[Karmabet] Misconfiguration of 'karmabet_savemode', falling back to SQLite!")
else
print("[Karmabet] SQLite Module has been loaded." .. i)
i = i + 1
end
...
...
end
hook.Add( "Think", "karmabet_sqlite_think", loadSQLite( nil ) )
hook.Add( "karmabet_loadsqlite", "karmabet_sqlite_call", loadSQLite( true ) )
For some odd reason the server now prints this during loading BEFORE being fully initialized:
[Karmabet] SQLite Module has been loaded.1
[Karmabet] SQLite Module has been loaded.2
You see how I defined
i as 1 at the top, incrementing it upon printing the message? Well yeah, it gets printed twice. Why does it do that? I mean, it is only a visual problem, the plugin itself seems to be working fine after it, but just for debugging's sake... why?
Lastly it should be noted that the function loadSQLite is not called from outside (since it's local) except by the hook inside the mysql script which - BEFORE connecting to MySQL - checks the convars if they've changed from default:
if DATABASE_HOST == "none" or DATABASE_NAME == "none" or DATABASE_USERNAME == "none" or DATABASE_PASSWORD == "none" then
print("[Karmabet][ERROR] Your MySQL Database Settings are missing!")
print("[Karmabet][ERROR] Your MySQL Database Settings are missing!")
print("[Karmabet][ERROR] Your MySQL Database Settings are missing!")
print("[Karmabet][ERROR] Loading SQLite Module instead!")
hook.Call( "karmabet_loadsqlite" )
return false
end
But then again this piece of code is only run when the server "Think"s, which it is not since sv_hibernate_think is not set to 1 and nobody's connected or connecting, so technically when using "sqlite" anyway this hook is also never run, yet it prints the message mentioned before two times.
Any ideas?
And while I'm at it... I should go to sleep now. Maybe I get a "Geistesblitz" in the morning, only to notice that I overlooked something quite basic while messing with the stuff here. Thanks again for the valuable help
