Lua Reference Troubleshooting

Enginseer

Salientia of the Community Patch
Supporter
Joined
Nov 7, 2012
Messages
3,674
Location
Somewhere in California
So, I'm making some Lua coding for some future mods and the functions work all fine and the new bug-fix on dummy policies by whoward69 should be hopefully okay to do, but anyway. The function below is designed to detect an event choice. If an event is chosen, grant a dummy policy and revoke the original dummy policy. Now, this is great but the event does however loop, so the policy that needs to be revoked might not be there anymore.

Question is how do I get it to revoke any dummy policies?


Let's per se, all civilizations had the original 1st government civic. India picks the 2nd government civic and the function then revokes the original 1st government civic and grants India the 2nd civic. A few turns pass and now India has decided to choose the 4th government civic. How would I code the function to make it revoke the 2nd civic and any other interchangeably rather than being stuck to one variable to which it only revokes the 1st government civic?



Code:
function EventChosen(iPlayer, iChoice)
	local pPlayer = Players[iPlayer]
	if iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_1 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_DEPOTISM, true)
	elseif iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_2 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_HEREDITARY_RULE, true)
	elseif iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_3 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_PATRONAGE, true)
	elseif iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_4 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_REPRESENTATION, true)
	elseif iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_5 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_POLICE_STATE, true)
	elseif iChoice == GameInfoTypes.PLAYER_EVENT_GOVERNMENTCIVIC_CHOICE_6 then
		pPlayer:RevokePolicy(iPolicy)
		pPlayer:GrantPolicy(GameInfoTypes.POLICY_CIVIC_UNIVERSAL_SUFFRAGE, true)
	end
end
GameEvents.EventChoiceActivated.Add(EventChosen)
 
Assuming choice N grants policy X, where

1 -> A
2 -> B
3 -> C
4 -> D
5 -> E
6 -> F

AND you can only have ONE of A, B, C, D, E or F

revoke(A)
revoke(B)
revoke(C)
revoke(D)
revoke(E)
revoke(F)

if (choice == 1) then grant(A)
elseif (choice == 2) then grant(B)
elseif (choice == 3) then grant(C)
elseif (choice == 4) then grant(D)
elseif (choice == 5) then grant(E)
elseif (choice == 6) then grant(F)
 
So, basically revoke everything before I do the checks?
 
Back
Top Bottom