Python errors in CvGameUtils.py

wotan321

Emperor
Joined
Oct 25, 2001
Messages
1,228
Location
NC, USA
I am working on a scenario for RI in which I want to delay the ability to declare wars until a certain date/turn number. I can achieve this is BTS by editing the candeclarewar line in CvGameUtils and the BugGameUtils.py files.

But in RI I am getting many python errors with the same code. What am I missing? Any help is greatly appreciated.
 
Well, one thing off the top of my head is that USE_CAN_DECLARE_WAR_CALLBACK is set to 0 in PythonCallbackDefines.xml. Other than that, care to post the actual code that causes errors?
 
Thank-you for your attention to this. I did change that line in PythonCallbackDefines.xml to 1. I know this will turn out to be something annoyingly simple but I cannot figure it out.

The code in CvGameUtils.py is:
Code:
    def canDeclareWar(self,argsList):
        iAttackingTeam, iDefendingTeam = argsList
        if CyGame().getGameTurn() <= 221:
            return False
        else:
            return True
The indenting appears exactly the same as in other mods that work.

What I am getting in the log file PythonErr2.log is:

Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 17, in ?
File "<string>", line 52, in load_module
File "BugEventManager", line 102, in ?
File "<string>", line 52, in load_module
File "CvEventManager", line 12, in ?
File "<string>", line 52, in load_module
File "CvScreensInterface", line 21, in ?
File "<string>", line 52, in load_module
File "CvDanQuayle", line 8, in ?
File "<string>", line 35, in load_module
File "<string>", line 13, in _get_code
File "CvGameUtils", line 66
SyntaxError: 'return' outside function
 
Aaaargh! Okay, it was the difference between a space and a tab, it appears. I did a little research and found the error message on one other thread, and they noted that python knows the difference between 4 spaces and a tab. So in my text editor, Notepad ++, you can show the tabs and whitespaces in the file, and those lines were the only unusual occurrences of spaces. So I changed that... and no error message.
 
Okay.... the error messages stopped, but it doesn't work. Are there any other files that control the turning off the ability to declare war?

Again, thanks for all the help.
 
So, once again let me say thanks.

I mod this game so infrequently that I never get a big understanding of the mechanics, and once I find a solution I move on. These problems I am having are probably common knowledge to you folks who do this frequently and thoroughly.

My scenario of for a WW2 map of Europe. I want it to begin in the mid 30s and war is not possible until a few years later. So I have the scenario start in the industrial era, but I set it to "GameTurn=0" and then in my CvGameUtils file say that declaring war can start AFTER turn 221. I launch the scenario and I am able to declare war on the first turn, which tells me it is not working.

I went back to some saved scenarios in the Worldbuilder folder that I had saved on earlier starts and I noticed in that file, the scenario started on turn 600 or something like that, instead of turn 1. So of course my 221 delay would not work. I changed the CvGameUtil.py line from 221 to 721 and then launched the scenario and now I cannot declare war. I guess setting the era to Industrial pads the turn count?

Anyway, my next goal is to see if I can use that If statement in the CvGameUtil.py file to only fire on that WW2 scenario file.
 
So glad you figured that one out! Unfortunately, I can be of very limited help when it comes to Python stuff; I know quite little of it myself. I'm more an art assets guy.
 
Anyway, my next goal is to see if I can use that If statement in the CvGameUtil.py file to only fire on that WW2 scenario file.
Identifying the scenario is tricky, at least I was only able to solve it indirectly.
Like checking for a civ/leader which is only present in the given scenario.
The check itself might need some new c++ functions, I don't remember if there are usable checks for this in vanilla Civ IV.
 
Top Bottom