Help with python

Joined
Jul 5, 2004
Messages
23,562
Location
Canberra, Australia
I usually learn a new language by either building something new or doing maintenance, it has worked for the last 30 years :) so I have tried to modify RoM to add in two other mods "Great People" and "zEnslavement". Both had good descriptions of what I should do to merge them in.

I did the merge, one at a time. However nothing happend!

So I put what I thought were trace prints in. Even those did not work.

Then I started from scratch with just the trace prints and still nothing happens.

What am I doing wrong?

The code fragment from the where I should put "zEnslavement" follows.


Spoiler :
def onCombatResult(self, argsList):
'Combat Result'

#Start - Trace
CvUtil.pyPrint( 'onCombatResult event in CvEventManager.py happens' )
#End - Trace

pWinner,pLoser = argsList
playerX = PyPlayer(pWinner.getOwner())
unitX = PyInfo.UnitInfo(pWinner.getUnitType())
playerY = PyPlayer(pLoser.getOwner())
unitY = PyInfo.UnitInfo(pLoser.getUnitType())
if (not self.__LOG_COMBAT):
return
if playerX and playerX and unitX and playerY:
CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s'
%(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(),
playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))



Is there any documentation on the CvUtil class and its pyPrint method?
 
I usually learn a new language by either building something new or doing maintenance, it has worked for the last 30 years :) so I have tried to modify RoM to add in two other mods "Great People" and "zEnslavement". Both had good descriptions of what I should do to merge them in.
Are you modifying the file in the RoM mod directory, in CustomAssets, or somewhere else? To make sure your changes are being seen, I'd advise changing the RoM files directly (after backing them up, of course.)

Is there any documentation on the CvUtil class and its pyPrint method?
The only documentation for it is whatever comments are in CvUtil.py itself (and in this case it isn't much.) In terms of General API documentation, all we really have to go on are the comments supplied by pydoc and copying examples of existing code. Anyhow, first make sure all the logging options are turned on in your Civilization IV.ini file. Then anything passed to CvUtil.pyPrint() will be printed to the file PythonDbg.log and prefaced with "PY:". So, in your example the following statement should appear in PythonDbg.log:
Code:
PY:onCombatResult event in CvEventManager.py happens
The logs appear in the Logs subdirectory of the My Games subdirectory for the particular game you're modding (e.g. "...MyGames\Beyond the Sword\Logs" if BTS). You also want to check PythonErr.log in that same place; any syntax or runtime errors will be listed there with a stack trace.

Depending on your needs, you can also output messages in-game by using CyInterface().addImmediateMessage(strMessage, None).

BTW, when posting code blocks please use
Code:
 tags (which can then be wrapped in [spoiler] tags too if necessary). Since indentation is critical in Python, it really helps to see code with the exact formatting intact; even if you attach the actual file some of us are lazy and just look at the posted text. ;)
 
Great this is helping. :goodjob:

I have been changing the code in the RoM directories after I got a strange xml error early on. I have reduced the number of backups on my machine to 2 from 5 :crazyeye:

One problem I have encountered and fixed was that my installation of IDLE seems to have two values for the tab. Tabs which are in the loaded file are 8 characters long but those I type in are only 3 characters long. But they become 8 again when I reload the file :eek:

I don't seem to be getting all the logs so I must have missed one or more of the of the settings. Also I am getting a PythonErr2.log not a PythonErr.log. At least I now know that it is getting to the zEnslavement call, if not returning from it.
 
Can't help with IDLE since I use Emacs for my Python editing. In terms of logging, PythonErr2.log is basically just environment information. You should have a PythonErr.log as well; however that file may not always get generated if you don't overwrite logs and there weren't any errors. I generally just have all of the logging options on in the INI even though it's more than normally necessary:
Code:
; Enable the logging system
LoggingEnabled = 1

; Enable synchronization logging
SynchLog = 1

; Enable rand event logging
RandLog = 1

; Enable message logging
MessageLog = 1

I also have old logs be overwritten so they don't get huge but that's a personal preference.
Code:
; Overwrite old network and message logs
OverwriteLogs = 1
 
Thanks, I have all those options turned on. Still no log files, Python.Err or PythonDbg.log.

It must be something else I have done :). I am great at misunderstanding unclear or incomplete instructions. That's why I an used to test such things at work.
 
Are you looking in the right place? "My Documents\My Games\Beyond the Sword\Logs" is where they are stored. You found PythonErr2.log, so I would think so. While the error log will be empty if there were no errors, the debug log says when each Python module is loaded, so it will always have content.
 
Yep, I am looking in My Documents\My Games\Beyond the Sword\Logs.

There are four files in that directory all with the correct date time stamp. They are init.log,
PythonErr2.log,resmgr.log (which is empty), and xml.log.
 
Just to be thorough, let's make sure you have turned on logging in the right INI file since there's a separate one for each game but they are all named the same. In this case, make sure the previously posted logging options are set in ...\My Games\Beyond the Sword\Civilization IV.ini If that's already correct, then, err, I'm not sure what else to try.
 
Yes that is the INI file I have changed.

It did not originally have a line for
Code:
ShowPythonDebugMsgs = 1
so I put it an the end of the ini file.

And what about?

Code:
; Establish connection to Python Debugger
HAPDebugger = 0

Should I be changing this? It is the only line I can find that mentions the Python Debugger.
 
And what about?

Code:
; Establish connection to Python Debugger
HAPDebugger = 0

Should I be changing this? It is the only line I can find that mentions the Python Debugger.

That's for remote debugging and you shouldn't change it unless you're using an IDE with remote debugging capabilities.
 
Top Bottom