Building Table Access

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
I'm having an issue with this code:

Code:
function PopulateRelBuildingsTb()
	for row in GameInfo.Buildings() do
		local iBuildingType = GameInfo.Buildings[row.Type].ID
		local pBuildingType = GameInfo.Buildings[row.Type].Type
		if GameInfo.Building_ResourceYieldChanges{BuildingType = pBuildingType, YieldType = "YIELD_FAITH"} then
			table.insert(RelBuildingsTb, iBuildingType)
		end
	end
	for i, v in pairs(RelBuildingsTb) do
		print("[PopulateRelBuildingsTb] " ..i, v)
	end
end

It is supposed to retrieve all buildings that produce Faith and insert them into a table, but I get a total of 142 buildings added. I tried adding ", Yield > 1}" to the end of line #5, but it breaks when the Yield is null.


Also, on another note. GameEvents.CityConstructed() doesn't seem to be working for me, it doesn't fire at all and the game is updated.
 
I'm doing this in the mod I'm working on to pull the building names for a class of buildings out of the <Buildings> table, and to stick them into a table along with a resource name and a modifier amount:
Code:
function InsertBuildingForBuildingClassIntoTable(sTableName, sBuildingClassType, sResourceType, iProductionModifier)
	--get building(s) for buildingclass
	for row in GameInfo.Buildings() do
		local sBuildingName = tostring(row.Type)
		local sBuildingClassName = tostring(row.BuildingClass)
		if sBuildingClassName == sBuildingClassType then
			if sTableName[sBuildingName] == nil then
				sTableName[sBuildingName] = {}
			end
			sTableName[sBuildingName][sResourceType] = iProductionModifier
		end
	end
end
I'm not directly using the ID numbers, but I would think if I did this:
Code:
function InsertBuildingForBuildingClassIntoTable(sTableName, sBuildingClassType, sResourceType, iProductionModifier)
	--get building(s) for buildingclass
	for row in GameInfo.Buildings() do
		local [COLOR="Blue"]iBuilding = GameInfoTypes[tostring(row.Type)][/COLOR]
		local sBuildingClassName = tostring(row.BuildingClass)
		if sBuildingClassName == sBuildingClassType then
			if sTableName[[COLOR="blue"]iBuilding[/COLOR]] == nil then
				sTableName[[COLOR="blue"]iBuilding[/COLOR]] = {}
			end
			sTableName[[COLOR="blue"]iBuilding[/COLOR]][sResourceType] = iProductionModifier
		end
	end
end
It would ought to work, though I am not interested in Faith-generating buildings. [edit] and now that I think about it I could probably go more direct with simply using
Code:
[COLOR="Blue"]iBuilding = row.ID[/COLOR]

But if you are interested in buildings that produce Faith why are you looking at Building_ResourceYieldChanges ? Why also attempt to look at Building_ResourceYieldChanges as a subset of Buildings within your lua ? Why are you not looking at Building_YieldChanges and Building_ResourceYieldChanges directly ? And for that matter, why are you not also looking at Building_FeatureYieldChanges, Building_SeaPlotYieldChanges, etc. ?

---------------------------------------------------------------------------------------------

GameEvents.CityConstructed.Add(xxxx) seems to be working for me so far.
 
Back
Top Bottom