Militia

Your config XML is essentially empty. The <mod> element is just the top-level grouping element that gives the mod a unique ID, but you need an <event> element here to hook up your event.

Code:
<mod id="Militia" module="Militia">
    <event type="ImprovementBuilt" function="onImprovementBuilt"/>
</mod>

The module must match the name of your Python file minus the .py extension. The type must match the string from CvEventManager. And the function must match the name of the function in your module.

The details for this are on the events tutorial page you linked. Follow the example all the way. :)
 
Your config XML is essentially empty. The <mod> element is just the top-level grouping element that gives the mod a unique ID, but you need an <event> element here to hook up your event.

Code:
<mod id="Militia" module="Militia">
    <event type="ImprovementBuilt" function="onImprovementBuilt"/>
</mod>

The module must match the name of your Python file minus the .py extension. The type must match the string from CvEventManager. And the function must match the name of the function in your module.

The details for this are on the events tutorial page you linked. Follow the example all the way. :)

Gah! I forgot to scroll down.. AGAIN!
 
Rats! Still not putting out the trace print so still not calling onImprovementBuilt! A farm is an improvement isn't it?

Included Militia.py, init.xml, Caste System Militia.xml, and PythonDbg.log.
 
Okay, I can see from PythonDbg.log that your event is being registered:

Code:
17:45:32 DEBUG: BugConfig - loading mod file Caste System Militia
17:45:32 DEBUG: BugInit - loading mod Caste System Militia...
17:45:32 INFO : BugCore - creating uninitialized mod Militia
17:45:32 DEBUG: BugUtil - looking up Militia.onImprovementBuilt
load_module Militia

17:45:32 DEBUG: BugEventManager - adding event '[B][COLOR="Red"]ImprovementBuilt[/COLOR][/B]'
17:45:32 DEBUG: Timer - load mod [Caste System Militia] took 2 ms

And looking in CvEventManager I see that the event type is not correct. As stated in the tutorial the event type must match what's there exactly--including case.

Code:
'[B][COLOR="Red"]improvementBuilt[/COLOR][/B]' 		: self.onImprovementBuilt,

You must change the type in your XML file to match "improvementBuilt" with a lowercase "i" at the start.
 
@StrategyOnly,

If you haven't guessed, all you need to do in your original code is change this line

Code:
		eventManager.addEventHandler("ImprovementBuilt", self.onImprovementBuilt)

to

Code:
		eventManager.addEventHandler("[COLOR="Red"][B]i[/B][/COLOR]mprovementBuilt", self.onImprovementBuilt)
 
You got to be kidding me, thats all the problem was, i used a CAPITAL I, instead of a small i, WOW now that is some picky stuff, i want to personally thx everyone who helped out, especially Dancing H, for knowing what the heck people are talking about and finding possible errors.

I still just cant believe it was something that small that caused all this, i have tried over 5 months to figure this out, just plain WOW!!:crazyeye:
 
OK been testing this new stuff out and i just got this error message?

Traceback (most recent call last):
File "BugEventManager", line 361, in _handleDefaultEvent
File "Militia", line 54, in onImprovementBuilt

Spoiler :
Code:
if (pPlayer.isCivic(charity)==True):
				era = pPlayer.getCurrentEra ()
				BugUtil.debug("Milita mod - Farm built, Civic is Charity, Era is %s.",  era)
				if (era == gc.getInfoTypeForString( "ERA_MEDIEVAL" )):
					#~ militia = gc.getInfoTypeForString( 'UNIT_MILITIA_MEDIEVAL' )
					[B]pNewUnit = pPlayer.initUnit( self.militiaMedieval, iX, iY, UnitAITypes.UNITAI_RESERVE, DirectionTypes.NO_DIRECTION )
				elif (era == gc.getInfoTypeForString( "ERA_RENAISSANCE" )):
					#~ militia = gc.getInfoTypeForString( 'UNIT_MILITIA_RENAISSANCE' )[/B]
					pNewUnit = pPlayer.initUnit( elf.militiaRenaissance, iX, iY, UnitAITypes.UNITAI_RESERVE, DirectionTypes.NO_DIRECTION )
				elif (era == gc.getInfoTypeForString( "ERA_INDUSTRIAL" )):
					#~ militia = gc.getInfoTypeForString( 'UNIT_MILITIA_INDUSTRIAL' )
					pNewUnit = pPlayer.initUnit( self.militiaIndustrial, iX, iY, UnitAITypes.UNITAI_RESERVE, DirectionTypes.NO_DIRECTION )
				elif (era == gc.getInfoTypeForString( "ERA_MODERN" )):
					#~ militia = gc.getInfoTypeForString( 'UNIT_MILITIA_MODERN' )
					pNewUnit = pPlayer.initUnit( self.militiaModern, iX, iY, UnitAITypes.UNITAI_RESERVE, DirectionTypes.NO_DIRECTION )
				CyInterface().addMessage(iPlayer,False,15,localText.getText("TXT_RECRUITED",()),'',0,'Art/Interface/Buttons/Civics/Serfdom.dds',ColorTypes(44), iX, iY, True,True)
###Militia End###


NameError: global name 'elf' is not defined
 
Fix for the "No Such Module" XXXXXXXX error message

I have discovered the exact answer for the "No Such Module" error that sometimes affects new mods merged with BUG. If the python file has even one bad "import" reference at the top of the file, the Civ4 python interpreter will fail to parse it correctly and give a "No Such Module" error message, even though the file actually does exist. Again it is not that the file is missing, but rather a python mistake made within the referenced python file. I have duplicated this error and fixed it simply by adding and removing a bad import reference.

In my case, I had two bad import references within my OGIGameUtils.py file. Once I removed the bad references, the error went away.

Bottom Line is: When you get the "No Such Module" error, you likely have a python error in the referenced python file.
 
To be fair, this error comes from the Python interpreter used in Civ4--not BUG. :) When you tell Python to import a module, it is an error if that module doesn't exist.
 
To be fair, this error comes from the Python interpreter used in Civ4--not BUG. :) When you tell Python to import a module, it is an error if that module doesn't exist.

Yes. Bad assumption on my part. BUG is off the hook and I have changed the post. I'm just glad I figured this out, as I have run across this error many times. Its a tricky error as the module can exist, but with a python error.
 
Back
Top Bottom