Mission and Function problem

bane_

Howardianism High-Priest
Joined
Nov 27, 2013
Messages
1,559
This is the relevant part of the mission:

Code:
...
    local pPlayer = Players[Game.GetActivePlayer()];
	local pPlot = unit:GetPlot()
	local iPlotOwner = pPlot:GetOwner()	
	GameEvents.PlayerDoTurn.Add(BondsHFood(pPlayer, iPlotOwner))
...

This is from the function:
Code:
function BondsHFood(pPlayer, iPlotOwner)
	for _, v in ipairs(pPlayer:GetTradeRoutes()) do
		local pFromCity = v.FromCity
		local pToCity = v.ToCity
		local pToCityOwner = Players[pToCity:GetOwner()]
		if pToCity:GetOwner() == Players[iPlotOwner] then
			local FFood = math.ceil(pFromCity:GetFood() / 50)
			local TFood = math.ceil(pToCity:GetFood() / 50)
			print("OUR FromFood pre-increase is " .. pFromCity:GetFood() .. ".")
			print("OUR ToFood pre-increase is " .. pToCity:GetFood() .. ".")
			pFromCity:ChangeFood(FFood)
			pToCity:ChangeFood(TFood)
			print("OUR FromFood now is " .. pFromCity:GetFood() .. ".")
			print("OUR ToFood now is " .. pToCity:GetFood() .. ".")
		end
	end
	for _, v in ipairs(Players[iPlotOwner]:GetTradeRoutes()) do
		local pFromCity = v.FromCity
		local pToCity = v.ToCity
		local pToCityOwner = Players[pToCity:GetOwner()]
		if pToCity:GetOwner() == pPlayer then
			local FFood = math.ceil(pFromCity:GetFood() / 50)
			local TFood = math.ceil(pToCity:GetFood() / 50)
			print("FromFood pre-increase is " .. pFromCity:GetFood() .. ".")
			print("ToFood pre-increase is " .. pToCity:GetFood() .. ".")
			pFromCity:ChangeFood(FFood)
			pToCity:ChangeFood(TFood)
			print("FromFood now is " .. pFromCity:GetFood() .. ".")
			print("ToFood now is " .. pToCity:GetFood() .. ".")
		end
	end
	local BondsTimer = BondsTimer + 1
	if BondsTimer == 15 then
		GameEvents.PlayerDoTurn.Remove(BondsHFood)
	end
end

The turn after I activate the mission, (thus, including BondsHFood into the PlayerDoTurn) I get a CTD. Nothing on the Lua log. :(

This is one of the last fixes before I can launch my next Civ, I'm working on it for a month now.

Ideas? Please?
 
It's probably because you set a GameEvents hook to run a function with variables passed to it. I've never tried doing this, but it sounds like a bad idea. GameEvents already pass variables (in the case of PlayerDoTurn, just iPlayer) to the functions they call, so there is likely some sort of conflict there.

Rewrite the GameEvents hook to just have the name of the function (with no parentheses), and define your pPlayer and your iPlotOwner variables during the function instead.
 
Top Bottom