Condition being ignored

JFD

Kathigitarkh
Joined
Oct 19, 2010
Messages
9,132
Location
The Kingdom of New Zealand
In the following code, I'm looking to convert my civ to the first religion founded (so long as that religion isn't founded by my civ). This works fine, but the check that's meant to stop it from happening every turn after the conversion event isn't working.

Spoiler :

Code:
function JFDArmenianConversion(playerID)
local doOnce = false
  if not doOnce then	
    for i, iPlayer in pairs(Players) do
      if iPlayer:IsEverAlive() then
        if iPlayer:GetReligionCreatedByPlayer() > 0 then
	local maxNumReligionsAllowed = GameInfo.Worlds[Map.GetWorldSize()].MaxActiveReligions
	local religionsFounded					
	  if iPlayer:GetCivilizationType() == GameInfoTypes["CIVILIZATION_JFD_ARMENIA"] then
	     religionsFounded = 2
	  else
	     religionsFounded = 1
	  end
					
	 if Game.GetNumReligionsStillToFound() == (maxNumReligionsAllowed - religionsFounded) then
	    for z, zPlayer in pairs(Players) do
	       if zPlayer:IsEverAlive() and zPlayer:GetCivilizationType() ~= GameInfoTypes["CIVILIZATION_JFD_ARMENIA"] then
		  if zPlayer:GetReligionCreatedByPlayer() > 0 then
		    firstReligion = zPlayer:GetReligionCreatedByPlayer() 
		    local religiousFounder = Game.GetFounder(firstReligion, -1)
		    religiousLeader = Players[religiousFounder]	
		    JFDConvertArmenia(playerID)
		    doOnce = true
end
end
end
end
end
end
end
end
end
GameEvents.PlayerDoTurn.Add(JFDArmenianConversion)


The value of doOnce changes to true after the code is finished, but the check that it must not be true is simply ignored. I have tried various different means of checking that doOnce is not true, including doOnce ~= true, which is frequently used by Firaxis. So, before I resign to some dirty method by using a dummy policy or building, I was hoping someone could point out what I might be doing wrong. Thanks.
 
Code:
function JFDArmenianConversion(playerID)
    local doOnce = false
    if not doOnce then
Seriously... :)?

You can also turn this function off:
Code:
GameEvents.PlayerDoTurn.Remove(JFDArmenianConversion)
 
Back
Top Bottom