• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days (this includes any time you see the message "account suspended"). For more updates please see here.

Lua woes

Hiram

XML Plebian
Joined
Dec 14, 2006
Messages
1,088
Location
Where The Streets Have No Name
I've been having issues playing with mods lately where particular unit or civ abilities created in Lua code do not run. Is there any way to find a log for this to see what might be the source of the problem? I use a lot of mods so a manual option isn't terribly practical.

Edit: from doing a bit of reading I've learned that there is apparently a bug involving the line "GameEvents", which could possibly have something to do with it. I don't know much at all about Lua so I have no idea.
 
Enable logging, then look at lua.log - it will at least show if any of the lua files are failing with errors
 
Enable logging, then look at lua.log - it will at least show if any of the lua files are failing with errors

Could runtime errors in the Lua of one mod cause the Lua of other mods not to be loaded?

I'm seeing this quite prominently throughout the log:

Spoiler :
Code:
[28165.964] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28166.292] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28166.588] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28166.947] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28167.290] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28167.602] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28168.070] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28168.507] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28168.835] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28169.147] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28169.474] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28169.771] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28170.067] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28170.410] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28170.722] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28171.019] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28171.315] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28171.658] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28171.986] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28172.282] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28172.626] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28172.922] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28173.250] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28173.562] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28173.858] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28174.154] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28174.420] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28174.747] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28175.059] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28175.356] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)
[28175.652] Runtime Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\Tibetan Civilization (BNW) (v 1)\Lua/TibetUA.lua:60: attempt to index local 'leaderTrait' (a nil value)

Could this be the cause of some Lua files not being loaded?
 

Attachments

Could runtime errors in the Lua of one mod cause the Lua of other mods not to be loaded?

Unlikely.

But these are going to cause problems

Code:
[COLOR="Red"][27973.724] Syntax Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\The Kingdom of Italy (v 2)\Lua/MareNostrum01.lua:18: function arguments expected near ':'
[27973.724] Runtime Error: Error loading C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\The Kingdom of Italy (v 2)\Lua/MareNostrum01.lua.[/COLOR][27973.740] FestiveUnit: This is the 'We Love the King Day - Musician' mod script.
[27973.740] SecondPantheonBelief: This is the Second Pantheon Belief mod script.
[27973.756] ChooseGPspecialist: This is the 'Choose GP specialist' mod script.
[27973.756] FreeBuildingonTech: The Free Building on Tech for Argentina Lua loaded succesfully
[27973.771] TraitMigration: Loaded Nri Immigration
[27973.771] Mali Mod: Slavery
[COLOR="red"][27973.771] Runtime Error: Assets\DLC\Expansion2\UI\InGame\InGame.lua:1258: attempt to index local 'addinFile' (a nil value)
[27973.771] Runtime Error: Error loading Assets\DLC\Expansion2\UI\InGame\InGame.lua.[/COLOR]

Especially the second, as it looks like one of the mods you're using has replaced the core InGame.lua file and broken it
 
Unlikely.

But these are going to cause problems

Code:
[COLOR="Red"][27973.724] Syntax Error: C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\The Kingdom of Italy (v 2)\Lua/MareNostrum01.lua:18: function arguments expected near ':'
[27973.724] Runtime Error: Error loading C:\Users\Ben\Documents\My Games\Sid Meier's Civilization 5\MODS\The Kingdom of Italy (v 2)\Lua/MareNostrum01.lua.[/COLOR][27973.740] FestiveUnit: This is the 'We Love the King Day - Musician' mod script.
[27973.740] SecondPantheonBelief: This is the Second Pantheon Belief mod script.
[27973.756] ChooseGPspecialist: This is the 'Choose GP specialist' mod script.
[27973.756] FreeBuildingonTech: The Free Building on Tech for Argentina Lua loaded succesfully
[27973.771] TraitMigration: Loaded Nri Immigration
[27973.771] Mali Mod: Slavery
[COLOR="red"][27973.771] Runtime Error: Assets\DLC\Expansion2\UI\InGame\InGame.lua:1258: attempt to index local 'addinFile' (a nil value)
[27973.771] Runtime Error: Error loading Assets\DLC\Expansion2\UI\InGame\InGame.lua.[/COLOR]

Especially the second, as it looks like one of the mods you're using has replaced the core InGame.lua file and broken it

So it has something to do with UI? That would be user interface, not unique improvement, yeah?

I looked at the InGame.lua file and the error comes in somewhere around here:
---------------------------------------------------------------------------------------
-- Support for Modded Add-in UI's
---------------------------------------------------------------------------------------
g_uiAddins = {};
for addin in Modding.GetActivatedModEntryPoints("InGameUIAddin") do
local addinFile = Modding.GetEvaluatedFilePath(addin.ModID, addin.Version, addin.File);
local addinPath = addinFile.EvaluatedPath;

-- Get the absolute path and filename without extension.
local extension = Path.GetExtension(addinPath);
local path = string.sub(addinPath, 1, #addinPath - #extension);

table.insert(g_uiAddins, ContextPtr:LoadNewContext(path));
end

I've got no idea because none of the mods I'm using appear to replace the InGame.lua file.
 
I've got no idea because none of the mods I'm using appear to replace the InGame.lua file.

Then one of the mods probably has an InGameUIAddin entry for a non-existent file
 
I've updated the Italy mod, which will alleviate one of your problems. It's possible the Tibet mod is using the outdated method of hiding dummy buildings, as was I. I've since changed this for Irkalla's method, so perhaps there was a conflict.
 
These kind of errors come from the fact that a lot of mods declare their main lua files as "InGameUIAddin" entry points, which will crash the game's InGame.lua script preventing it from loading other, legitimate "InGameUIAddin" entry point mods.
"InGameUIAddin" entry points are only for lua contexts which need to be displayed as a layer in the InGame context, using paired lua / xml files, and declare the xml file only.
 
These kind of errors come from the fact that a lot of mods declare their main lua files as "InGameUIAddin" entry points, which will crash the game's InGame.lua script preventing it from loading other, legitimate "InGameUIAddin" entry point mods.
"InGameUIAddin" entry points are only for lua contexts which need to be displayed as a layer in the InGame context, using paired lua / xml files, and declare the xml file only.

InGameUIAddin is one of the main entrypoints if you want your mod to have any lua code running that isn't a part of an existing Lua context in the UI (ie, not replacing an existing file), not necessarily only for new UI screens. (You could implement a UA using a lua script that was an InGameUIAddin, no problem.) This approach is much more modular since any number of Lua files from different mods can be executed using their own InGameUIAddin entries, whereas each core file can only be replaced by a single mod at a time (and when multiple replace the same file, it's anyone's guess which will actually be loaded and likely cause issues with one of the two or both mods).

I'm not sure what you mean about the process of including Lua files with InGameUIAddin crashing InGame.lua. By putting in an InGameUIAddin entry for a file that doesn't exist in your mod, you'll crash InGame.lua (as we see above), but as long as the syntax of your added files is correct, it won't take out InGame.lua when loading.
 
If it's only an lua script, it doesnt need to be in an entry point.

Then how else would its code actually run? You can use VFS=true and include it in another lua file, but there needs to be a starting point where it's included in something that will be executed.

From whoward's reference thread, particularly the second to last point:

.lua - Lua Script
  • Is the file a replacement for a core game file?
    • VFS: True
  • Is the file part of a new UI context (but not a scenario load screen)?
    • VFS: False
    • Either this Lua file or it's associated XML file requires an InGameUIAddin entry
  • Is the file part of a new Scenario Load Screen context?
    • VFS: False
    • Either this Lua file or it's associated XML file requires a Custom entry
  • Is this a map script?
    • VFS: True
    • Requires a MapScript entry
  • Does this file contain methods registered by events within the file, or methods that are then executed directly during game startup?
    • VFS: False
    • Requires an InGameUIAddin entry
  • Does this file contain methods used by other Lua files and is included into those other Lua files?
    • VFS: True

Not to mention I've done this many times in mods with no issues.
 
Does this file contain methods registered by events within the file, or methods that are then executed directly during game startup?
VFS: False
Requires an InGameUIAddin entry[/URL]
Check how Firaxis does it for their own scenarii, this is not needed: lua code is run if it's listed in the mod's modinfo file list.
And the related InGame.lua crashes are rarely noticed simply because the crash occurs at the very end of the InGame.lua script, the only effect is to stop further InGameUIAddin entries from loading.
Of course Firaxis should have used pcall to load the addins... but that's another story.
 
Check how Firaxis does it for their own scenarii, this is not needed. The code is run if it's listed in the mods file list. And the related InGame.lua crashes are rarely noticed simply because the crash occurs at the very end of the script, and of course also because it does not cause an InGame.lua load failure. But then of course Firaxis should have used pcall...

Firaxis' own scenarios are Custom Games, not mods, and those have their own very specific set of requirements and special start-up sequence that by-passes the need for InGame addins - see http://forums.civfanatics.com/showthread.php?t=433336 for full details
 
It is also very easy to confirm that an InGame addin is required and setting VFS=true is not enough.

Download the "My - Changes (v 1)" mod from my website, or from the link in my sig, and start a game with it enabled, you will see two lines in lua.log like

Code:
[28351.512] MyLuaChanges: This is the 'My - Changes' mod script
[28351.512] MyUiAddition: This is the 'My - Changes (UI Context)' mod script

Exit civ and edit the "My - Changes (v 1).modinfo" file as follows

1) change the import value to 1 for LUA/MyLuaChanges.lua, ie
Code:
<File md5="FB6AB8AE6C2C409D5E0FC3155A27FAB3" import="[B][COLOR="Red"]1[/COLOR][/B]">LUA/MyLuaChanges.lua</File>

2) delete the block
Code:
<EntryPoint type="InGameUIAddin" file="LUA/MyLuaChanges.lua">
  <Name>My Changes</Name>
  <Description>My Changes</Description>
</EntryPoint>

which has the same effect as removing the InGame addin and setting VFS=true in ModBuddy

Now restart Civ and start a game, you will only get one line in lua.log

Code:
[28351.512] MyUiAddition: This is the 'My - Changes (UI Context)' mod script

indicating that the code in the "LUA/MyLuaChanges.lua" file has NOT been executed
 
Firaxis's code does not have VFS=true (i.e. import="0") in those cases. Would that make a difference ?

If you mean for the scenario start-up lua file, then no, as the start-up sequence effectively runs the same "load and execute" code that's in InGame.lua for loading mod InGame addins.

Bottom line, if you want a standalone Lua file to execute it MUST have an InGameUiAddin entry. (The VFS setting for such a file is actually irrelevant, but good practice is NOT to set VFS=true, unfortunately the first version of ModBuddy set EVERY file to import="1", which is why you'll find many, many examples where VFS=true has been set unnecessarily)
 
Back
Top Bottom