Pazyryk
Deity
- Joined
- Jun 13, 2008
- Messages
- 3,584
It's rather annoying that errors in SQL or XML just cause the file not to load (silently) rather than give you an explicit error message. Sure, you can check the DB for every change you make. And it's always obvious after a while that something is wrong. But, really, this is the most common kind of error in my modding. I want instant feedback. Like this:
Or, if all is well, then this:
I set this up in my mod as follows:
Create a new SQL file called DebugTableCheck.sql. Add it as an OnModActivated and make sure it loads before all of your other SQL/XML. Contents:
At the last line of every SQL file you want to test, add a line like this (blue text is unique name for the file):
You can do the same for an XML file like this:
Now, all you have to do is check that all of the expected files are present somewhere in your Lua init code. In mine, it looks like this:
This saves me minutes every time I start civ for another testing session, which may be 100 times a week I guess...
Code:
EaMain: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
EaMain: !!!! ERROR: UnitPromotions.sql was not loaded to end of file !!!!
EaMain: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Or, if all is well, then this:
Code:
EaMain: All expected SQL and XML files loaded to end of file...
I set this up in my mod as follows:
Create a new SQL file called DebugTableCheck.sql. Add it as an OnModActivated and make sure it loads before all of your other SQL/XML. Contents:
Code:
CREATE TABLE EaDebugTableCheck ('FileName' TEXT NOT NULL);
At the last line of every SQL file you want to test, add a line like this (blue text is unique name for the file):
Code:
INSERT INTO EaDebugTableCheck(FileName) SELECT '[COLOR="Blue"]UnitPromotions.sql[/COLOR]';
You can do the same for an XML file like this:
Code:
<EaDebugTableCheck>
<Row FileName="[COLOR="blue"]EaText_Help.xml[/COLOR]"/>
</EaDebugTableCheck>
Now, all you have to do is check that all of the expected files are present somewhere in your Lua init code. In mine, it looks like this:
Code:
function OnLoadEaMain()
--check to make sure all expected SQL files were loaded to end of file
local expectedSQLfiles = { 'EaImages.sql', --from Ea Media Pack
'EaActions.sql',
'EaAI.sql',
'EaRaces.sql',
'EaCivsAndTraits.sql',
'EaPeople.sql',
'EaCreations.sql',
'AI.sql',
'Buildings.sql',
'Civilizations.sql',
'GameInfo.sql',
'GlobalDefines.sql',
'Policies.sql',
'Religions.sql',
'Technologies.sql',
'Terrain.sql',
'UnitControl.sql',
'UnitPromotions.sql',
'Units.sql',
'EaText.sql',
'EaText_Actions.xml',
'EaText_Civs.xml',
'EaText_Help.xml',
'EaText_Misc.xml',
'EaText_Pedia.xml',
'EaText_People.xml',
'EaText_Units.xml' }
local bAnyErrors = false
for i = 1, #expectedSQLfiles do
local expectedFile = expectedSQLfiles[i]
local bLoaded = false
for row in GameInfo.EaDebugTableCheck() do
if expectedFile == row.FileName then
bLoaded = true
break
end
end
if not bLoaded then
bAnyErrors = true
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("!!!! ERROR: "..expectedFile.." was not loaded to end of file !!!!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
end
end
if not bAnyErrors then
print("All expected SQL and XML files loaded to end of file...")
end
end
--at end of file
OnLoadEaMain()
This saves me minutes every time I start civ for another testing session, which may be 100 times a week I guess...