Script requires mod to be reloaded before running.

lilgamefreek

Warlord
Joined
Oct 30, 2014
Messages
229
I seem to attract the strangest bugs.

Working on a new mod that runs an entirely new script. The bizarre thing is the script always fails to load on its first instance (verified through lua logs). My general workflow on debugging this script has been:

->start game
->load mod
->setup match and start
->quit to main menu
->reload mod
->setup match and start
->actually test the script

Closing the game resets the cycle. Rebuilding the mod while in the main menu does not. Absolutely bizarre, any thoughts? Clearly this is a problem before release. :/

You can examine the compiled mod here:
https://www.dropbox.com/s/sqa97ahy32gx4lt/The Spartans (v 1).zip?dl=0

Special thanks to JFD for his custom civ detection function. Everything else in the script is written by me. The script provides a free instance of basic units when they are researched, which is why I've boosted the science stupidly high for debug purposes. Script works, with a few bugs.

Issue is still in progress
 
How are you hooking your script into the game? If you aren't using "InGameUIAddin" try that out and see if it fixes the problem (even if your script has absolutely nothing to do with the UI). Do you have VFS on or off? You should only have it set to true if you're replacing an existing .lua script (or you're adding a new asset such as artwork or music). If you are using that hook, and you have VFS set properly, my next recommendation would be to zip your compiled mod and attach it to the OP.
 
I actually had vfs set to true! I'd been setting them all to true by default because I am lazy and needed it as true for my previous mod which did replace a pre-existing lua. I'll try that out. InGameUIAddIn has been around since the start!

edit: No changes to report. :( Mod has been posted in OP
 
Gonna do a quick re-ping. Must ask, would this be a better question for the main civ5 modding forum? It doesn't seem like a problem that would be specific to BE, but I also don't want to break any forums rules.
 
Debugging process:

Loading the mod, quitting back to menu before setting up a game, reloading the mod: Script Successful

Loading an independent mod, quitting back to menu before setting up a game, reloading mod of interest: Script Successful

Loading an independent mod with a script and mod of interest simultaneously, setting up a game: Independent mod's script successful, mod of interest's script unsuccessful

Starting unmodded game, quitting back to menu, loading the mod: Script unsuccessful

It would be much appreciated if someone could verify that this isn't a local problem by launching the mod on their own machine. I'll rebuild the latest version I'm using. The fastest way to verify is to setup a game with The Spartans, be sure to explicitly select your cargo to NON-weaponscache, and see if you spawn with a soldier or not.

https://www.dropbox.com/s/sqa97ahy32gx4lt/The Spartans (v 1).zip?dl=0
 
I can confirm that simply loading the mod and starting a game does not award you with the free unit. Additionally, I can confirm that loading the mod, backing out to the menu, then re-loading the mod and starting a game does cause the unit to spawn. In neither case did the text "The Spartans are in this game" appear in the Firetuner Lua Console, so I'd start there...

Feel free to add more print dialogues all over the script until you can figure it out. You can even output variables etc. (and with string.format() it's even possible to do basic formatting on how the variables appear; %d is an integer, %.f or %.6f are decimals [in the latter case being out to the 6th digit]; %s is a string [which typically requires you to wrap the variable in the tostring() function; this is useful for outputting boolean values]).
 
Thanks for the confirmation and the tip! I hadn't thought of rechecking JFD's code library and had failed to consider debugging those segments. I figured out the error! For future reference:

Code:
local civilisationID = GameInfoTypes["CIVILIZATION_SPARTANS"]
Was returning nil. Thus it never matched with actual spartan factions (whom had id 12 in my test setup). I fixed this by changing to:

Code:
local civilisationID = GameInfo.Civilizations["CIVILIZATION_SPARTANS"].ID
 
Top Bottom