Dancing Hoskuld
Deity
Not a problem both the init.xml and the "Caste System Militia.xml" files
<mod id="Militia" module="Militia">
<event type="ImprovementBuilt" function="onImprovementBuilt"/>
</mod>
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.![]()
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
'[B][COLOR="Red"]improvementBuilt[/COLOR][/B]' : self.onImprovementBuilt,
eventManager.addEventHandler("ImprovementBuilt", self.onImprovementBuilt)
eventManager.addEventHandler("[COLOR="Red"][B]i[/B][/COLOR]mprovementBuilt", self.onImprovementBuilt)
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
Obvious typo
elf.militiaRenaissance
elf should be self.
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.