Where did i go wrong in this Lua?

Firebug

Not-so Great Engineer
Joined
Sep 25, 2014
Messages
1,271
Location
Clevedon, England
This is what i'm attempting to make.

Each We Love the King Day decreases :c5angry: Unhappiness from number of cities by 15%


Logs aren't showing any errors, the dummy building does work (i was able to spawn it in using ingame editor), but yet triggering a WLTKD doesn't spawn the dummy building.
I've used other mod's WLTKD scripts as reference to what should be done, and i came up with this.

Code:
	function BulgariaTrait(playerID)
print("Bulgaria function is running")
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_BULGARIA"] and player:IsAlive() then
		for city in player:Cities() do
		if (pCity:GetWeLoveTheKingDayCounter() > 0) then
			if (not city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 1);
			end
		else 
			if city:IsHasBuilding(GameInfoTyupes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 0);
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(BulgariaTrait)

print("my lua loaded to the end")

but it doesn't work. Where did i go wrong?
 
'pCity' is your problem, on this line
Code:
if (pCity:GetWeLoveTheKingDayCounter() > 0) then
Everywhere else you are using 'city'.

Ah, oops. I'll test it now, thanks for the fast reply.

Edit: So apparently, that changed nothing. the dummy building still doesn't spawn when a city enters a WLTKD.

I'll post both the dummy and lua.


The building - which works when i spawn it in using ingame editor.
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
  <Buildings>
	  <Row>
		  <Type>BUILDING_TRAIT_UNHAPPINESS</Type>
		  <BuildingClass>BUILDINGCLASS_TRAIT_UNHAPPINESS</BuildingClass>
		  <Cost>-1</Cost>
		  <FaithCost>-1</FaithCost>
		  <GreatWorkCount>-1</GreatWorkCount>
		  <CityCountUnhappinessMod>-15</CityCountUnhappinessMod>
	  </Row>

	</Buildings>
	<BuildingClasses>
		<Row>
			<Type>BUILDINGCLASS_TRAIT_UHAPPINESS</Type>
			<DefaultBuilding>BUILDING_TRAIT_UNHAPPINESS</DefaultBuilding>
		</Row>

	</BuildingClasses>
</GameData>

The Lua code that has no errors in the log but doesn't work.

Code:
	function BulgariaTrait(playerID)
print("Bulgaria function is running")
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_BULGARIA"] and player:IsAlive() then
		for city in player:Cities() do
		if (City:GetWeLoveTheKingDayCounter() > 0) then
			if (not city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 1);
			end
		else 
			if city:IsHasBuilding(GameInfoTyupes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 0);
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(BulgariaTrait)

print("my lua loaded to the end")
 
'City' is your problem, on this line
Code:
if (City:GetWeLoveTheKingDayCounter() > 0) then
Everywhere else you are using 'city'.

Hint hint LUA is case sensitive.
 
'City' is your problem, on this line
Code:
if (City:GetWeLoveTheKingDayCounter() > 0) then
Everywhere else you are using 'city'.

Hint hint LUA is case sensitive.


Welp.
Thanks! I'll give that a go too now.
 
Code:
Syntax Error: C:\Users\Rich\Documents\My Games\Sid Meier's Civilization 5\MODS\Firebug's Bulgaria (v 1)\Lua/BulgTrait.lua:16: 'then' expected near ')'
Runtime Error: Error loading C:\Users\Rich\Documents\My Games\Sid Meier's Civilization 5\MODS\Firebug's Bulgaria (v 1)\Lua/BulgTrait.lua.

Code:
	function BulgariaTrait(playerID)
print("Bulgaria function is running")
	local player = Players[playerID]
	if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_BULGARIA"] and player:IsAlive() then
		for city in player:cities() do
		if (city:GetWeLoveTheKingDayCounter() > 0) then
			if (not city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 1);
			end
		else 
			if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
				city:SetNumRealBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"], 0);
				end
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(BulgariaTrait)

print("my lua loaded to the end")

I'm still having issues with this code. The building is fine, that works because i can spawn it in with Ingame Editor, but the lua still doesn't spawn the building during WLTKDs.
 
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0)

Unnecessary parenthesis somewhere as recorded in the lua.log *cough*
 
Missing a ( or have an extra ) on this line

Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0[B][COLOR="Red"][SIZE="5"])[/SIZE][/COLOR][/B] then
 
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0)

Unnecessary parenthesis somewhere as recorded in the lua.log *cough*

The lua log says
Code:
'then' expected near ')

That's supposed to tell me theres an unnecessary paranethesis?
*COUGH*




Missing a ( or have an extra ) on this line

Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0[B][COLOR="Red"][SIZE="5"])[/SIZE][/COLOR][/B] then

Thanks, i'll check that.
 
That's supposed to tell me theres an unnecessary paranethesis?

Get yourself NotePad++, it understands Lua and will syntax highlight the code for you - makes finding typos oh so much easier
 
Get yourself NotePad++, it understands Lua and will syntax highlight the code for you - makes finding typos oh so much easier

I have notepad++ but was not aware that i could use it for looking a lua errors and stuff.
 
The lua log says
Code:
'then' expected near ')

That's supposed to tell me theres an unnecessary paranethesis?
*COUGH*

Yes, expect the LUA error logs to be read like how a computer reads it.
When it begins to process your LUA, the computer remains content until
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0)
The computer reads this instead as
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"])
It ignores the "> 0" part because the first parenthesis closes the code already, there isn't a second "(" so it assumes that this line of code is done. It then finds an error on what to do next and assumes that you might have forgotten about the "if.. then.." statement and tells you to put a 'then near )', so it would want you to edit the code as
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) [B]then[/B]

But you don't want that, you need the '> 0", so what you have two solution: Deleting the unnecessary parenthesis or adding in the second parenthesis to conclude the line of code, so either one will work, assuming you're not checking if there's more than one building aside.
Code:
if [B]([/B]city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) > 0) then
or
Code:
if city:IsHasBuilding(GameInfoTypes["BUILDING_TRAIT_UNHAPPINESS"]) then


On another note the "player:cities()" section might foreshadow another error since Civilization V looks for player:Cities() of the code, but I could be wrong.
 
I already fixed it after Whoward told me i could use Notepad++. so now the UA is finished.
But thanks for the help anyway, you wrote a lot there.
 
Back
Top Bottom