What's wrong with this code?

Androrc the Orc

Emperor
Joined
Apr 19, 2004
Messages
1,621
Location
Vienna, Austria
I made the following alteration in CityView.lua (changes in red):

Code:
		sortedList = {};
		thisId = 1;
		for building in GameInfo.Buildings() do
			local thisBuildingClass = GameInfo.BuildingClasses[building.BuildingClass];
[COLOR="Red"]			-- Androrc
--			if thisBuildingClass.MaxGlobalInstances <= 0 and thisBuildingClass.MaxPlayerInstances ~= 1 and thisBuildingClass.MaxTeamInstances <= 0 then
			if thisBuildingClass.MaxGlobalInstances <= 0 and thisBuildingClass.MaxPlayerInstances ~= 1 and thisBuildingClass.MaxTeamInstances <= 0 and not thisBuildingClass.Hidden then
			-- Androrc End
[/COLOR]				local buildingID= building.ID;
				if pCity:GetNumSpecialistsAllowedByBuilding(buildingID) <= 0 then
					if (pCity:IsHasBuilding(buildingID)) then
						numBuildingsInThisCity = numBuildingsInThisCity + 1;
						local element = {};
						local name = Locale.ConvertTextKey( building.Description )
						element.name = name;
						element.ID = building.ID;
						sortedList[thisId] = element;
						thisId = thisId + 1;
					end
				end
			end
		end

It is supposed to make it so buildings that belong to building classes that have the "Hidden" field set to true not appear in the city screen. However, this code is making it so ZERO non-specialist buildings appear in the city view screen. Does anybody have any idea of what might be wrong with it?

This is my SQL alteration that adds the "Hidden" field to building classes, by the way:

Code:
ALTER TABLE BuildingClasses ADD COLUMN 'Hidden' TEXT DEFAULT false;

Strangely enough, I wrote very similar code for the civilopedia screen (to exclude "Hidden" building classes' buildings from showing up in the civilopedia), and that worked perfectly.
 
The Hidden column that you created is of text type, so when you use it as a condition it always returns true if there is some text in it, even if this text is saying 'false' :)
 
A quote from this page: http://www.sqlite.org/datatype3.html

SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

It's an interesting thing that Civ5 XML files use the boolean data type, it seems it's converted to integer (0 or 1) when filling the database with data. So I think you should make it an integer value, and use 0 as false and 1 as true. I'm not sure how it will work in LUA conditions though, so it's possible that instead of
Code:
not thisBuildingClass.Hidden
you'll have to use
Code:
thisBuildingClass.Hidden == 0
 
A quote from this page: http://www.sqlite.org/datatype3.html



It's an interesting thing that Civ5 XML files use the boolean data type, it seems it's converted to integer (0 or 1) when filling the database with data. So I think you should make it an integer value, and use 0 as false and 1 as true. I'm not sure how it will work in LUA conditions though, so it's possible that instead of
Code:
not thisBuildingClass.Hidden
you'll have to use
Code:
thisBuildingClass.Hidden == 0

That worked perfectly! Thank you so much :)
 
Top Bottom