I cannot get Lua to load for me mod at all

I made a couple of minor changes to the code here to tighten up and to add a couple of things so that the code only runs when the civ is actually part of a game, but otherwise there was nothing to debug really because there is nothing really wrong with code or the mod as posted on Post #5 (other than the couple of changes already mentioned, which I included into the code as posted here and which were active when I tested).

Both the mod and the lua code itself work just fine for me.
Spoiler :
Code:
print("Started Mental script")

local iCiv = GameInfoTypes.CIVILIZATION_MENTAL
local iCargo = GameInfoTypes.UNIT_CARGO_SHIP
local iCaravan = GameInfoTypes.UNIT_CARAVAN
local iPietyPolicy1 = GameInfoTypes.POLICY_ORGANIZED_RELIGION
local iPietyPolicy2 = GameInfoTypes.POLICY_REFORMATION
local iPietyBranch = GameInfoTypes.POLICY_BRANCH_PIETY

local iMentalPromotion = GameInfoTypes.PROMOTION_MENTAL_HOARD


--This stuff was borrowed and modified from other Civ, in this case:
--Hakurei Shrine

-------------------------------------------------------------------------------------------------------------------------
-- GetStrongestMilitaryUnit
-------------------------------------------------------------------------------------------------------------------------
function GetStrongestMilitaryUnitStrengthM(pPlayer, bIgnoreResources, ...)
	local tUnit = {["Combat"] = 0}
	for iKey, sCombatType in pairs(arg) do
		for row in GameInfo.Units("CombatClass = \'" .. sCombatType .. "\'") do
			if pPlayer:CanTrain(row.ID, bIgnoreResources) and row.Combat > tUnit.Combat then
				tUnit = row
			end
		end
	end
	return tUnit.Combat
end

print("Mentals Lua: GetStrongestMilitaryUnitStrengthM")

function MentalStrength(pPlayer,iPower)
	if (pPlayer:IsAlive()) then
		for pUnit in pPlayer:Units() do
			if (pUnit:IsHasPromotion(iMentalPromotion)) then
				local tUnitData = GameInfo.Units[pUnit:GetUnitType()]
				local iBaseCombatStrength = tUnitData.Combat
				local iBaseRangedCombatStrength = tUnitData.RangedCombat
				local iModifiedCombatStrength = math.ceil(iBaseCombatStrength * (1+(iPower/10)))
				local iModifiedRangedCombatStrength = math.ceil(iBaseRangedCombatStrength * (1+(iPower/10)))
				pUnit:SetBaseCombatStrength(iModifiedCombatStrength)
			end
		end	

		if pPlayer:IsHuman() then
			pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "This is a test: Unit Power at: "..iPower, -1, -1);
		end
	
	end
end

print("Mentals Lua: MentalStrength")

function UpdateMentalPolicy(iPlayer)
	print("Testing")
	local pPlayer = Players[iPlayer]
	if (pPlayer:IsAlive()) and (pPlayer:GetCivilizationType() == iCiv) then
		print("Mental has "..pPlayer:GetNumPolicies().." policies")
		MentalStrength(pPlayer,pPlayer:GetNumPolicies())
	end
end

print("Mentals Lua: UpdateMentalPolicy")

------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end
------------------------------------------------------------
---- GameEventHooks
------------------------------------------------------------
if IsCivInPlay(iCiv) then
	GameEvents.PlayerAdoptPolicy.Add(UpdateMentalPolicy);
	GameEvents.PlayerDoTurn.Add(UpdateMentalPolicy);
end

print("Mentals Lua: Hooks are loaded!")

print("Mentals Lua is loaded and ready!")
If you were expecting GameEvents.PlayerAdoptPolicy to fire when you open a policy branch, it does not. It only fires when you select the actual policies within a policy branch. Nor will it fire reliably when directly giving yourself policies via an lua method, via IGE, or via Live Tuner. You actually need to use the Pre-Provided Policy Selection Pop-up to get GameEvents.PlayerAdoptPolicy to fire reliably.

Relevent portions of my file Lua.log:
  1. From Game Loading:
    Code:
    [1343298.406] MentalLua: Started Mental script
    [1343298.406] MentalLua: Mentals Lua: GetStrongestMilitaryUnitStrengthM
    [1343298.421] MentalLua: Mentals Lua: MentalStrength
    [1343298.421] MentalLua: Mentals Lua: UpdateMentalPolicy
    [1343298.421] MentalLua: Mentals Lua: Hooks are loaded!
    [1343298.421] MentalLua: Mentals Lua is loaded and ready!
  2. After using IGE to give me enough culture to both open a policy-branch and select a policy from within the policy-branch:
    Code:
    [1343409.015] MentalLua: Testing
    [1343409.015] MentalLua: Mental has 2 policies
  3. The free floater unit had ist combat power changed to '5' from '4' (rouding up of 4 * 1.2 = 4.8)

----------------------------------------------

There is a slight goof in the code for the player notification in that the argument position for the 1st "-1" is actually meant for the text string for the general description of the notification message, such as "Free Unit" or something.:
Code:
local sLongMessage = " Message message message message to tell us [COLOR_NEGATIVE_TEXT]What Bad Thing Has Happened[ENDCOLOR]"
local sShortMessage = "[COLOR_POSITIVE_TEXT]We Have A Message![ENDCOLOR]"
pPlayer:AddNotification(NotificationTypes["NOTIFICATION_GENERIC"], sLongMessage, sShortMessage)
The trailing parameters aren't really required for a "NOTIFICATION_GENERIC" because for that particular type of notification the game makes no use of them.

------------------------------------------------

The process I use to test whether a PlayerAdoptPolicy listener is firing correctly is to give myself a bunch of culture in IGE, then close out IGE, then use the normal selection pop-up menu to select a policy.

-------------------------------------------------

Also, GameEvents.PlayerAdoptPolicyBranch(PlayerID, PolicyBranchID) fires when you adopt a policy branch, but it does not fire when you select an ideology in BNW.
 
I made a couple of minor changes to the code here to tighten up and to add a couple of things so that the code only runs when the civ is actually part of a game, but otherwise there was nothing to debug really because there is nothing really wrong with code or the mod as posted on Post #5 (other than the couple of changes already mentioned, which I included into the code as posted here and which were active when I tested).

Both the mod and the lua code itself work just fine for me.
Spoiler :
Code:
print("Started Mental script")

local iCiv = GameInfoTypes.CIVILIZATION_MENTAL
local iCargo = GameInfoTypes.UNIT_CARGO_SHIP
local iCaravan = GameInfoTypes.UNIT_CARAVAN
local iPietyPolicy1 = GameInfoTypes.POLICY_ORGANIZED_RELIGION
local iPietyPolicy2 = GameInfoTypes.POLICY_REFORMATION
local iPietyBranch = GameInfoTypes.POLICY_BRANCH_PIETY

local iMentalPromotion = GameInfoTypes.PROMOTION_MENTAL_HOARD


--This stuff was borrowed and modified from other Civ, in this case:
--Hakurei Shrine

-------------------------------------------------------------------------------------------------------------------------
-- GetStrongestMilitaryUnit
-------------------------------------------------------------------------------------------------------------------------
function GetStrongestMilitaryUnitStrengthM(pPlayer, bIgnoreResources, ...)
	local tUnit = {["Combat"] = 0}
	for iKey, sCombatType in pairs(arg) do
		for row in GameInfo.Units("CombatClass = \'" .. sCombatType .. "\'") do
			if pPlayer:CanTrain(row.ID, bIgnoreResources) and row.Combat > tUnit.Combat then
				tUnit = row
			end
		end
	end
	return tUnit.Combat
end

print("Mentals Lua: GetStrongestMilitaryUnitStrengthM")

function MentalStrength(pPlayer,iPower)
	if (pPlayer:IsAlive()) then
		for pUnit in pPlayer:Units() do
			if (pUnit:IsHasPromotion(iMentalPromotion)) then
				local tUnitData = GameInfo.Units[pUnit:GetUnitType()]
				local iBaseCombatStrength = tUnitData.Combat
				local iBaseRangedCombatStrength = tUnitData.RangedCombat
				local iModifiedCombatStrength = math.ceil(iBaseCombatStrength * (1+(iPower/10)))
				local iModifiedRangedCombatStrength = math.ceil(iBaseRangedCombatStrength * (1+(iPower/10)))
				pUnit:SetBaseCombatStrength(iModifiedCombatStrength)
			end
		end	

		if pPlayer:IsHuman() then
			pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, "This is a test: Unit Power at: "..iPower, -1, -1);
		end
	
	end
end

print("Mentals Lua: MentalStrength")

function UpdateMentalPolicy(iPlayer)
	print("Testing")
	local pPlayer = Players[iPlayer]
	if (pPlayer:IsAlive()) and (pPlayer:GetCivilizationType() == iCiv) then
		print("Mental has "..pPlayer:GetNumPolicies().." policies")
		MentalStrength(pPlayer,pPlayer:GetNumPolicies())
	end
end

print("Mentals Lua: UpdateMentalPolicy")

------------------------------------------------------------
---- WilliamHoward's IsCivInPlay
------------------------------------------------------------

function IsCivInPlay(iCivType)
  for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    local iSlotStatus = PreGame.GetSlotStatus(iSlot)
    if (iSlotStatus == SlotStatus.SS_TAKEN or iSlotStatus == SlotStatus.SS_COMPUTER) then
      if (PreGame.GetCivilization(iSlot) == iCivType) then
        return true
      end
    end
  end
  
  return false
end
------------------------------------------------------------
---- GameEventHooks
------------------------------------------------------------
if IsCivInPlay(iCiv) then
	GameEvents.PlayerAdoptPolicy.Add(UpdateMentalPolicy);
	GameEvents.PlayerDoTurn.Add(UpdateMentalPolicy);
end

print("Mentals Lua: Hooks are loaded!")

print("Mentals Lua is loaded and ready!")
If you were expecting GameEvents.PlayerAdoptPolicy to fire when you open a policy branch, it does not. It only fires when you select the actual policies within a policy branch. Nor will it fire reliably when directly giving yourself policies via an lua method, via IGE, or via Live Tuner. You actually need to use the Pre-Provided Policy Selection Pop-up to get GameEvents.PlayerAdoptPolicy to fire reliably.

Relevent portions of my file Lua.log:
  1. From Game Loading:
    Code:
    [1343298.406] MentalLua: Started Mental script
    [1343298.406] MentalLua: Mentals Lua: GetStrongestMilitaryUnitStrengthM
    [1343298.421] MentalLua: Mentals Lua: MentalStrength
    [1343298.421] MentalLua: Mentals Lua: UpdateMentalPolicy
    [1343298.421] MentalLua: Mentals Lua: Hooks are loaded!
    [1343298.421] MentalLua: Mentals Lua is loaded and ready!
  2. After using IGE to give me enough culture to both open a policy-branch and select a policy from within the policy-branch:
    Code:
    [1343409.015] MentalLua: Testing
    [1343409.015] MentalLua: Mental has 2 policies
  3. The free floater unit had ist combat power changed to '5' from '4' (rouding up of 4 * 1.2 = 4.8)

----------------------------------------------

There is a slight goof in the code for the player notification in that the argument position for the 1st "-1" is actually meant for the text string for the general description of the notification message, such as "Free Unit" or something.:
Code:
local sLongMessage = " Message message message message to tell us [COLOR_NEGATIVE_TEXT]What Bad Thing Has Happened[ENDCOLOR]"
local sShortMessage = "[COLOR_POSITIVE_TEXT]We Have A Message![ENDCOLOR]"
pPlayer:AddNotification(NotificationTypes["NOTIFICATION_GENERIC"], sLongMessage, sShortMessage)
The trailing parameters aren't really required for a "NOTIFICATION_GENERIC" because for that particular type of notification the game makes no use of them.

------------------------------------------------

The process I use to test whether a PlayerAdoptPolicy listener is firing correctly is to give myself a bunch of culture in IGE, then close out IGE, then use the normal selection pop-up menu to select a policy.

-------------------------------------------------

Also, GameEvents.PlayerAdoptPolicyBranch(PlayerID, PolicyBranchID) fires when you adopt a policy branch, but it does not fire when you select an ideology in BNW.

Alright, I'll go ahead and update it, I was gonna do this anyway, but I do things one step at a time, and trying to get it to work was first ;)

The help is very much appreciated! But if the code is working just fine, then why is not working for me? Is there something that prevents it from working when it's freshly built?
That means that both logging is working and the mod file is reading the Lua so I did set it up right. But it's still not working for me at all, hmm.
I'd like to point out the FineTuner/Lua logs are printing stuff from other mods, so all that appears to be working.

Because my only guess for this another mod is stopping it, any ideas?

Oh and BTW, the each turn hooks are enough in my book, but I wanted it to be a little more dynamic for the script, so even if Ideologies doesn't work it's good enough IMO.

And finally, again, is there somewhere the game keeps track of what mods I'm using ATM, I really don't want to have to manually enable them all again when I'm done with my mod.
 
Is your mod even showing up at all in the leader selection screen ? There should be nothing about the mod that I can see that would keep it from working with another mod except that I know that people have had trouble getting custom civ mods to be loaded when "fake DLC" mods such as the NQmod multiplayer or some other multiplayer work-around mod is in the game's DLC folder. EUI generally does not cause conflict with other mods unless the other mod is using a custom version of UnitPanel.lua, CivtyView.lua, etc.

If you have other mods enabled, the best advice is to disable any mod not 100% essential to your mod. There are no such mods essential to yours that I know of based on the contents of your mod.

  1. Find these two files:
    • C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache/Civ5ModsDatabase.db
    • C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache/Civ5SavedGameDatabase.db
  2. Copy the files into a back-up location somewhere on your computer
  3. Delete all the files in the C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache folder.
  4. Make sure you have Steam in offline mode, because otherwise Steam will attempt to re-download all mods you have subscribed to on Steam.
  5. start the game and go into the mods menu
  6. you will now have a clean slate in the mods menu
  7. when you want to restore the list of mods that were previously active, simply copy the two files mentioned in #1 back into the C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache folder.

If you have the IGE mod it should be safe to enable that at the same time as your mod, because that is what I did.
 
Is your mod even showing up at all in the leader selection screen ? There should be nothing about the mod that I can see that would keep it from working with another mod except that I know that people have had trouble getting custom civ mods to be loaded when "fake DLC" mods such as the NQmod multiplayer or some other multiplayer work-around mod is in the game's DLC folder. EUI generally does not cause conflict with other mods unless the other mod is using a custom version of UnitPanel.lua, CivtyView.lua, etc.

If you have other mods enabled, the best advice is to disable any mod not 100% essential to your mod. There are no such mods essential to yours that I know of based on the contents of your mod.

  1. Find these two files:
    • C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache/Civ5ModsDatabase.db
    • C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache/Civ5SavedGameDatabase.db
  2. Copy the files into a back-up location somewhere on your computer
  3. Delete all the files in the C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache folder.
  4. Make sure you have Steam in offline mode, because otherwise Steam will attempt to re-download all mods you have subscribed to on Steam.
  5. start the game and go into the mods menu
  6. you will now have a clean slate in the mods menu
  7. when you want to restore the list of mods that were previously active, simply copy the two files mentioned in #1 back into the C:\Users\YourUserName\Documents\My Games\Sid Meier's Civilization 5\cache folder.

If you have the IGE mod it should be safe to enable that at the same time as your mod, because that is what I did.

Well, as I mentioned, every part of the mod will work (selecting it, playing as it, units buildings, the trait ext) Just not the Lua. I'll try what you suggested and see if I can get it to work on my end, thanks!

EDIT: Ok just tested it, it works! YES, so it was only mod blocking it.
So that leaves me to ask, why, and how would another mod block my Lua from running, is there a hard-coded Lua script limit or something, or is my mod conflicting with another (I did change the ID when I started, but left the mod buddy file name Civ5Mod1 mistakenly, did that affect it?)
 
To my knowlege there's no real limit to how many lua files can be running under "InGameUIAddin" at the same time. You will get conflict if your mod has the same ID # as another mod, so if you are not generating the mod in ModBuddy, but are rather directly creating the mod by editing the modinfo file, and folder and file names, etc., from a mod you copy/pasted as a "Starting Template", you could have caused the conflict in this way.

If your lua file has the same name as an lua file in another mod, this could concievably cause troubles depending on how the file in the other mod is being used, for example. But this is usually only a problem when both mods are trying to implement a custom version of the same base-game-file (such as the file that controls the Culture Overview pop-up).

In order to give a more meaningful answer, you'd have to isolate which mod is causing the conflict, because only then would there be any real chance to try to figure out what is the compatibility issue between the two mods.
 
To my knowlege there's no real limit to how many lua files can be running under "InGameUIAddin" at the same time. You will get conflict if your mod has the same ID # as another mod, so if you are not generating the mod in ModBuddy, but are rather directly creating the mod by editing the modinfo file, and folder and file names, etc., from a mod you copy/pasted as a "Starting Template", you could have caused the conflict in this way.

If your lua file has the same name as an lua file in another mod, this could concievably cause troubles depending on how the file in the other mod is being used, for example. But this is usually only a problem when both mods are trying to implement a custom version of the same base-game-file (such as the file that controls the Culture Overview pop-up).

In order to give a more meaningful answer, you'd have to isolate which mod is causing the conflict, because only then would there be any real chance to try to figure out what is the compatibility issue between the two mods.

Well then, I'll just randomize my mod's ID again, and start enabling mods one-by-one until I find the culprit. What I do know whatever mod is causing the problem doesn't have to be in the game to take effect, but there's about 40+ mods I gotta look through to find out :/
 
Back
Top Bottom