CvUtil.pyPrint not working in bat Mod ?

onkelm

Warlord
Joined
Aug 13, 2010
Messages
105
Hi,

I merged the "war machines" code from Platy into Bug Mod. it is working so far. Now I try to show a message like "unit %s was finished with +1XP by Player %d Civilization %s"

but I get always Python errors.
thats the code working:

def onUnitBuilt(self, argsList):
'Unit Completed'
city = argsList[0]
unit = argsList[1]
player = PyPlayer(city.getOwner())
## Training Center ##
if unit.getUnitCombatType() > -1:
iTrainRatio = 10 ## 1 XP per 10 of this unit built
iCount = CyStatistics().getPlayerNumUnitsBuilt(city.getOwner(), unit.getUnitType())
unit.changeExperience(iCount / iTrainRatio, 99999, False, False, False)

now I like to add this:
CvUtil.pyPrint('unit %s was finished with +1XP by Player %d in' %(pCity.getName()))

Any idea ?
 
Seems that you're not providing the player ID (for the %d).

Not sure I'd even bother with pyPrint. All it does is
Python:
def pyPrint(stuff):
	stuff = 'PY:' + stuff + "\n"
	sys.stdout.write(stuff)
A plain print also writes to stdout, which gets redirected to PythonDbg.log. One newline gets appended too; I guess pyPrint makes it two. BugUtil provides an actual logger (function names: trace, debug, info, warn, error) with levels configurable via the System tab of the BUG options screen. That should be the best approach for logging that stays in the code. Should also handle encoding problems (which might occur with methods like getName or getDescription) better than pyPrint/ print. I think BugUtil tries to discard special characters. On that note, one advantage of pyPrint over print is that one could still add better encoding support to pyPrint in the future.
 
Back
Top Bottom