Alrik2002
Warlord
In my mod I´ve some different EventManager.py-files, which I want to merge. In one file the following ModNetMessage is sent when the function onCityBuilt is called:
As you can see the function is within a class.
In the same .py-file the function "addBuildings" is defined.
I´ve tried to copy the parts to the CvEventManager.py. There is already a "onCityBuilt"-function, so I´ve copied the code to send the ModNetMessage there (the red one). This works as far I can see.
The part to define what should happen when this ModNetMessage is received, I´ve copied in the existing function "OnModNetMessage" in the CvEventManager.py (the blue one).
The function "addBuildings" I´ve just copied right beneath the function "onCityBuilt".
When I found a city, the following error occurs:
Line 331 is the red one in this part of the code:
Thank you again for your help!
Code:
class SettlersEventManager:
def __init__(self, eventManager):
eventManager.addEventHandler("cityBuilt", self.onCityBuilt)
eventManager.addEventHandler("ModNetMessage", self.onModNetMessage)
[COLOR="Red"]def onCityBuilt(self, argsList):
'City Built'
city = argsList[0]
if city.getOwner() == gc.getGame().getActivePlayer() :
pUnit = CyInterface().getHeadSelectedUnit() # note that if the unit is grouped,headUnit is not forced to be the settler
if pUnit:
iOwner = city.getOwner()
iCityID = city.getID()
iUnitClass = pUnit.getUnitClassType()
CyMessageControl().sendModNetMessage(167, iOwner, iCityID, iUnitClass, -1) # be sure 167 is not use for another mod net message, the best should be to add an id in CvUtil like for events[/COLOR]
[COLOR="Blue"]def onModNetMessage(self, argsList):
# 'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
iData1, iData2, iData3, iData4, iData5 = argsList
if iData1 == 167 :
addBuildings(iData2, iData3, iData4)
CvUtil.pyPrint( 'onModNetMessage' )[/COLOR]
As you can see the function is within a class.
In the same .py-file the function "addBuildings" is defined.
I´ve tried to copy the parts to the CvEventManager.py. There is already a "onCityBuilt"-function, so I´ve copied the code to send the ModNetMessage there (the red one). This works as far I can see.
The part to define what should happen when this ModNetMessage is received, I´ve copied in the existing function "OnModNetMessage" in the CvEventManager.py (the blue one).
The function "addBuildings" I´ve just copied right beneath the function "onCityBuilt".
When I found a city, the following error occurs:
Code:
Traceback (most recent call last):
File "BugEventManager", line 362, in _handleDefaultEvent
File "CvEventManager", line 331, in onModNetMessage
NameError: global name 'addBuildings' is not defined
Line 331 is the red one in this part of the code:
Code:
def onModNetMessage(self, argsList):
# 'Called whenever CyMessageControl().sendModNetMessage() is called - this is all for you modders!'
iData1, iData2, iData3, iData4, iData5 = argsList
if iData1 == 167 :
[COLOR="Red"]addBuildings(iData2, iData3, iData4)[/COLOR]
CvUtil.pyPrint( 'onModNetMessage' )
Thank you again for your help!