[BTS] Python doesnt trigger in MOD

Pir Lan Tota

Warlord
Joined
Jan 28, 2008
Messages
276
Location
Manchester
Hi guys,

so made mod for 3.17 (dvd version) of game by modding straight into the game files, not using a seperate MOD to load.

I am now building it into a proper mod that can be loaded seperately, which works, but the python code that works in 3.17 doesnt work in 3.19 (steam version). The code was already corrected by Nightinggale (Thanks again!), but somehow doesnt seem to trigger.

The code I am using in CvEventManager.py
https://forums.civfanatics.com/threads/plant-forest-mod-cant-get-it-to-work.621068/

I have attached the mod below. The code should trigger the changing of tree_nursery improvement into a forest.

PHP:
def onImprovementBuilt(self, argsList):
  'Improvement Built'
  iImprovement, iX, iY = argsList
  iForestType = CvUtil.findInfoTypeNum(gc.getFeatureInfo, gc.getNumFeatureInfos(),'FEATURE_FOREST')
  iNursery = CvUtil.findInfoTypeNum(gc.getImprovementInfo,gc.getNumImprovementInfos(),'IMPROVEMENT_TREE_NURSERY')
  if (iImprovement == iNursery):
    pPlot = CyMap().plot(iX, iY)
    pPlot.setFeatureType(iForestType, -1)
    pPlot.setImprovementType(-1)
  if (not self.__LOG_IMPROVEMENT):
    return
  CvUtil.pyPrint('Improvement %s was built at %d, %d'
    %(PyInfo.ImprovementInfo(iImprovement).getDescription(), iX, iY))
 

Attachments

You should use the log system to see if it triggers as intended.
PHP:
def onImprovementBuilt(self, argsList):
  'Improvement Built'
  print "Improvement built triggered"
That will print to PythonDbg.log if enabled. To enable, edit CivilizationIV.ini (it's in my documents/my games/Beyond the sword)
Recommended settings for python modders:
HidePythonExceptions = 0
DisableFileCaching = 1
DisableCaching = 1
LoggingEnabled = 1
MessageLog = 1
Now some interesting logs will appear inside the Logs folder next to the ini file. Perhaps the answer is that you encounter an exception, in which case the game will tell you which line and why it stop working.
 
Ok, done, ran the game, build the improvement, code didnt trigger. I attached both PythonDbg.log and PythonErr.log.

Had a look in PythonDbg.log, didnt see a mention of the onImprovementBuild action. The code you posted,

PHP:
def onImprovementBuilt(self, argsList):
  'Improvement Built'
  print "Improvement built triggered"

I add that to CvEventManager.py in my mod? Or to CvEventManager.py in BTS main folder?

Update: So I put in the same print command in original code, with slighty different text, it triggers the CvEventManager.py from BTS assets\python folder, not from mods\assets\python folder
Improvement built triggered_original Code
 

Attachments

Last edited:
OMG, I think I am a bloody idiot...I put the Python folder next to Assets, instead of in Assets....testing now


Yup, the bloody idiot award goes to me.....all fine now, I indeed put the Python folder in wrong location....aargh, sorry for wasting your time Nightinggale!
 
Last edited:
Back
Top Bottom