Calling multiple functions for "not IsHuman()"

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
I have created very many (7) functions in the following form:

Code:
function DenmarkAnglesWar()

	if Game.GetGameTurn() == 0 then

	----print(">>>> DeclareWar");
local DenmarkTeam
local AnglesTeam
local DenmarkTeamID
local AnglesTeamID

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 

local pDenmark = Players[iPlayer]

		if (pDenmark:IsAlive()) then
    --if (pDenmark:IsAlive() and not pDenmark:IsHuman()) then
		if (GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == pDenmark:GetCivilizationType()) then
		
	DenmarkTeamID = pDenmark:GetTeam();
	DenmarkTeam= Teams[ pDenmark:GetTeam() ]

	--print(pDenmark:GetName());
	--print(pDenmark:GetTeam());
	
	else
	end	
end
end

for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1, 1 do 

local pAngles = Players[iPlayer]

    if (pAngles:IsAlive()) then
		if (GameInfo.MinorCivilizations.MINOR_CIV_ANGLES.ID == pAngles:GetMinorCivType()) then
		
	AnglesTeamID = pAngles:GetTeam();
	AnglesTeam= Teams[ pAngles:GetTeam() ]
	
	--print(pAngles:GetName());
	--print(pAngles:GetTeam());
	
	else
end
end
end

DenmarkTeam:DeclareWar( AnglesTeamID, true );
DenmarkTeam:SetPermanentWarPeace(AnglesTeamID, true);
AnglesTeam:SetPermanentWarPeace(DenmarkTeamID, true);

if (DenmarkTeam:IsAtWar(AnglesTeamID)) then

print ("Denmark is at war with the Angles");

end
end
end

Events.ActivePlayerTurnEnd.Add(DenmarkAnglesWar)

I have rethought my objective in this and determined that I only want these Declarations of War to be for nonHuman players.

I have 7 such functions all set up in one file. I have attempted to alter each individually, but keep getting errors. It's likely because of bad organization in my coding, but when I add "not IsHuman" as part of the "if" statements, the function breaks down and doesn't work.

I am wondering, is there a simple way to nest these functions such that one greater function based upon the player being not human would call these lesser functions? I've tinkered with doing so, but again, failed. Is there an easy way to accomplish this?

My knowledge of Lua is limited, and when I start getting into functions within or calling other functions, I'm out of my depth. I'm hoping it is a simple process that is simply unknown to me.

Thank-you for your help.
 
"pDenmark:IsHuman()" is the code you want to use the problem in the example you have is that you're testing things in the wrong order/doing the test in the wrong place. There are a couple of ways you could structure it but here is one:

Code:
local Denmark = nil;

for index=0, GameDefines.MAX_MAJOR_CIVS-1 do
  if(GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == Players[index]:GetCivilizationType()) then
    Denmark = Players[index];
  end
end
After this for loop finishes you know (ignoring non-standard error cases) that the variable "Denmark" will be the player object for the Denmark civilization. You'll be able to use it to figure out if Denmark is a human player, alive and what their team is when it is time to declare war.

Code:
if(Denmark ~= nil and Denmark:IsAlive() and not Denmark:IsHuman) then
  local Angles = nil;

  for index=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_CIV_PLAYERS-1 do
    if(GameInfo.Civilizations.CIVILIZATION_DENMARK.ID == Players[index]:GetCivilizationType()) then
      Angles = Players[index];
    end
  end

  -- Declare war
  if(Angles ~= nil and Angles:IsAlive()) then
    Teams[Denmark:GetTeam()]:DeclareWar(Angles:GetTeam(), true );
    Teams[Denmark:GetTeam()]:SetPermanentWarPeace(Angles:GetTeam(), true);
    Teams[Angles:GetTeam()]:SetPermanentWarPeace(Denmark:GetTeam(), true);
  end
end
 
I'm not at home right now, but I can see that your methods are way more organised than mine.

Mine were so badly put together that any little alteration threw the thing out of whack. I'll correct it when I get home to reflect your improvements.

BTW, I think in the second half of the code, you meant to call the MINOR_CIV_ANGLES and not Denmark.

Thank you for the help.
 
You are absolutely correct, that "GameInfo.Civilizations.CIVILIZATION_DENMARK.ID" line in the second section of code should have been "GameInfo.Civilizations.MINOR_CIV_ANGLES.ID".
 
Back
Top Bottom