LUA Load Order, New XML data not recognized

kingchris20

Wisdom Seeker
Joined
Jul 30, 2012
Messages
1,343
Location
Resident of Heaven; Currently in the Waiting Room
Need some help again.

This code works perfectly (Thanks Ryika & AgressiveWimp)! But, only if the user loads the mod, backs out to the main menu so that "configuring game data" shows, and them reloads into the mod.

Code:
function CheckStargateUSAF(pPlayer)
	local ActivePlayer = Players[pPlayer]
	print(ActivePlayer:GetCivilizationType()) 
	print(GameInfoTypes["CIVILIZATION_STARGATE_USAF"])
	if ActivePlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_STARGATE_USAF"] then
		print ("ZPM Activation at 1,000 Energy")
		for iCity in Players[pPlayer]:Cities() do
			if (ActivePlayer:GetEnergy() >= 1000) then
				print ("Activating Shield of Atlantis!")
				iCity :SetNumRealBuilding(GameInfoTypes["BUILDING_SHIELD_OF_ATLANTIS"], 1) 
			else
				iCity :SetNumRealBuilding(GameInfoTypes["BUILDING_SHIELD_OF_ATLANTIS"], 0)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(CheckStargateUSAF)

My question is - Is there anyway to get this thing loaded and recognizing my new XMLs without the user having to back out to the main menu first?

My assumption is because the LUA references new XMLs. New XMLs get loaded when the mod is loaded, but I guess the LUA loads first and since the XMLs are loaded afterwards, the LUA doesn't recognize the new XMLs.

print(GameInfoTypes["CIVILIZATION_STARGATE_USAF"]) - this section of the code returns "nil" unless the user backs out to the main menu first..... if the user backs out to the main menu first, and reloads the mod, it returns the sponsor number as it should and works perfectly fine.
 
No, it doesn't have anything to do with the order in which files are loaded (All XML-Files get read into the database during the initial mod configuration, long before lua files even start to do anything).

What you're experiencing is a general database bug that is inherent to the game itself, whenever modders add new antries to some tables (including but not exclusive to Promotions and Builds (aka Worker actions)) the game just screws up and is unable to update stuff properly.

This bug has been around since the very release and as far as I know there is nothing we can do to fix that. Firaxis does not seem to care as is also evidenced by the "Lua Errors make the terrain go wild"-stuff that was then added on top of the problems that exist (which is sad, because looking at how Beyond Earth is structures one can tell that they've put a lot of effort in creating additional modability).

Ergo: Just add a note to the description that people will need to load mods twice and here and there somebody will actually read that instead of just leaving a comment on how nothing works the way it's supposed to work.
 
Back
Top Bottom