Lua file not parsing?

Mylon

Amateur Game Designer
Joined
Nov 4, 2005
Messages
1,013
I need some help getting into the Civ5 modding scene. I'm trying to add a fairly simple mod that makes culture from buildings based on population rather than being a flat value. As far as I can tell, my lua file isn't being used at all in the game as none of the print statements are showing up in Fire Tuner. Though I'm not sure if it's related, the code also displays somewhat oddly in Modbuddy; there's no ability to contract or expand blocks of code, but if I open another lua file/project (such as The Economy Mod) it shows up fine.

Here's the code I'm using:

Code:
print("LoadedCulturePerPopulation")

function UpdateCultureRate()

	print("Updating City Culture Per Turn from Buildings")

	local iPlayer = Players[Game.GetActivePlayer()]
			
	for pCity in iPlayer:Cities() do

		pCity:ChangeJONSCultureStored(1) --Simple debug, deleting this laster
				
		local NewCulture = 0
		local OldCulture = 0

		for row in GameInfo.Building_CultureChangePerPop() do
			
			if pCity:IsHasBuilding(GameInfo.Buildings[row.BuildingType].ID) then
				
				NewCulture += row.Culture * pCity.GetPopulation * pCity.GetCultureRateModifier() / 100

			end
		end

		for row in GameInfo.Buildings() do
			
			if pCity:IsHasBuilding(GameInfo.Buildings[row.BuildingType].ID) then

				OldCulture += row.Culture * pCity.GetCultureRateModifier()

			end
		end

		local TotalCulture = NewCulture + OldCulture

		-- Every turn we set Culture Per Turn from Buildings to 0 and re-calculate it.
		pCity:ChangeJONSCulturePerTurnFromBuildings(-pCity:GetJONSCulturePerTurnFromBuildings())
		pCity:ChangeJONSCulturePerTurnFromBuildings(TotalCulture)

	end
	
end

Events.ActivePlayerTurnStart.Add(UpdateCultureRate)

Note that Building_CultureChangePerPop is defined and I can reference it fine in firetuner. I also have set the lua file to import into the VFS. I've looked at other bits of lua code and I can't tell what I'm doing wrong.
 
It seems is what I'm missing is I need to add some XML code to reference and load the lua. I can probably just add this to my existing XML:

Code:
<Context Name="InGame">
<LuaContext FileName="ScriptFileName" ID="Scriptname" Hidden="True"/>
</Context>

And I'll be good to go. I'll give it a whirl.

Edit: Well, the IDE at least warned me I couldn't have two top-level blocks in the same file, so I made a new file and made sure to add it to the actions so it gets updated into the game, but still no luck. No culture coming from monument and no indication that the print command is even executing.
 
There's two different sorts of XML being confused here - UI XML and DB XML (there's also a variety of different XML types for graphics). You can use an appropriate addin type to get it in, or make a small mod to a vanilla file to define a new addin type (we're all hoping for some good community standards for that)

As long as your Lua is only affecting behaviour after world creation, there's no problem with using a UIAddin, other than the semantic strangeness.

The trick you're trying to emulate above is something I haven't done yet, so I don't know all the subtleties.
 
I added the lua file to a new line under InGameUIAddin in the content tab, but still no luck. It isn't so much that the code snippet isn't working as intended as that the print functions aren't working, which tells me the lua file isn't being loaded AT ALL. I'm finding this to be very frustrating. :(

The tutorials available seem to be all about copying existing UI code in its entirety to make changes. In the case of game logic code, like what I'm attempting here, I have not found a tutorial or guide on how to add code. And more puzzling is in studying say, the Economy Mod or NIGHTS, I cannot fathom how some of the code is loaded.
 
If you set your file to vfs true the print should absolutely show when it runs. Post your entire project and I will give it a look tonight
 
Nevermind. For some reason the InGameUIAddin didn't save! Now I'm at least seeing a line in the firetuner about an invalid syntax with +=, which is more than I've never seen before. Thanks for your patience.
 
Nevermind. For some reason the InGameUIAddin didn't save! Now I'm at least seeing a line in the firetuner about an invalid syntax with +=, which is more than I've never seen before. Thanks for your patience.

Just in case: Lua doesn't have any assignment operators apart from =
 
Back
Top Bottom