davidlallen
Deity
(I started this investigation by PM and it is probably here in the forum somewhere; but if I could not find it with some searching, perhaps others will benefit from this also.)
Problem: updated from old version of BUG (3.6) to new version (4.2) and the callbacks in my python/CvGameUtils.py stopped working. I added print statements and showed that they were no longer being called.
Solution:
1. Rename CvGameUtils.py to something else, and delete all the unmodified routines out of it. It usually contains dozens of "default" routines and a couple which you have modified. Keep all yours and delete all the rest. So if you had this file:
Rename it to MyModGameUtils.py and remove most of the other code:
Note I removed the unmodified function isVictory and changed the name of the module.
2. You need to tell BUG where to look for your modified functions. The key line is:
<gameutils module="MyModGameUtils" class="MyModGameUtils" override="True"/>
Most mods using BUG already have a file like Mods/<modname>/assets/Config/MyMod.xml which BUG uses to register things. If not, create it. Add this line. The smallest example I can see is FavoriteCivicDetector.xml; delete the "events" line and add the "gameutils" line.
Now, I still have some questions which hopefully others will find useful also.
a. File assets/xml/PythonCallbacks.xml disables a number of callbacks which are called millions of times, such as cannotMoveInto. Does BUG respect this, or do all of these callbacks get called?
b. The amount of python in my mod is "medium sized", less than 2000 lines. So far I have kept it all in one file and one class. It has a few dozen functions, of which about five are calls for CvGameUtils functions. Can I supply my main file + class to the gameutils call? In other words, will BUG get upset if there are functions in the gameutils class which have nothing to do with gameutils?
c. (This is more of a RevDCM question). My mod is built on top of other modcomps including RevDCM. A number of functions in CvGameUtils.py are modified by the RevDCM team and *not* further modified by me. I assume that I should just delete these functions from my MyModGameUtils.py file, because RevDCM has also updated to use this new BUG. True?
d. On the other hand, if there is some other small python modcomp which I have incorporated into my mod, I should probably keep their functions in MyModGameUtils. Or, at least find out if they have updated to BUG and get their files if so. True?
e. Suppose I have overridden five of the CvGameUtil functions and I want to use the default functions for the rest, and also my class contains many extra functions. How does BUG decide what to do? Does it search all the function names in my mod for matches with the default functions? Or do I have to give more information about which functions to use?
Problem: updated from old version of BUG (3.6) to new version (4.2) and the callbacks in my python/CvGameUtils.py stopped working. I added print statements and showed that they were no longer being called.
Solution:
1. Rename CvGameUtils.py to something else, and delete all the unmodified routines out of it. It usually contains dozens of "default" routines and a couple which you have modified. Keep all yours and delete all the rest. So if you had this file:
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Implementaion of miscellaneous game functions
from CvPythonExtensions import *
import CvEventInterface
import GodsOfOld
import Popup as PyPopup
import PyHelpers
# globals
gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer
class CvGameUtils:
"Miscellaneous game functions"
def __init__(self):
#RevolutionDCM - Inquisition Mod
self.revModEnabled = gc.getGame().isOption(GameOptionTypes.GAMEOPTION_REVOLUTION)
def isVictoryTest(self):
# Mymod: changed 10 to 100 (it is an example)
if ( gc.getGame().getElapsedGameTurns() > 10 ):
return True
else:
return False
def isVictory(self, argsList):
eVictory = argsList[0]
return True
Code:
## Sid Meier's Civilization 4
## Copyright Firaxis Games 2005
##
## Implementaion of miscellaneous game functions
from CvPythonExtensions import *
import CvEventInterface
import GodsOfOld
import Popup as PyPopup
import PyHelpers
# globals
gc = CyGlobalContext()
PyPlayer = PyHelpers.PyPlayer
class [COLOR="Red"]MyModGameUtils[/COLOR]:
"Miscellaneous game functions"
def __init__(self):
#RevolutionDCM - Inquisition Mod
self.revModEnabled = gc.getGame().isOption(GameOptionTypes.GAMEOPTION_REVOLUTION)
def isVictoryTest(self):
# Mymod: changed 10 to 100 (it is an example)
if ( gc.getGame().getElapsedGameTurns() > 100 ):
return True
else:
return False
2. You need to tell BUG where to look for your modified functions. The key line is:
<gameutils module="MyModGameUtils" class="MyModGameUtils" override="True"/>
Most mods using BUG already have a file like Mods/<modname>/assets/Config/MyMod.xml which BUG uses to register things. If not, create it. Add this line. The smallest example I can see is FavoriteCivicDetector.xml; delete the "events" line and add the "gameutils" line.
Now, I still have some questions which hopefully others will find useful also.
a. File assets/xml/PythonCallbacks.xml disables a number of callbacks which are called millions of times, such as cannotMoveInto. Does BUG respect this, or do all of these callbacks get called?
b. The amount of python in my mod is "medium sized", less than 2000 lines. So far I have kept it all in one file and one class. It has a few dozen functions, of which about five are calls for CvGameUtils functions. Can I supply my main file + class to the gameutils call? In other words, will BUG get upset if there are functions in the gameutils class which have nothing to do with gameutils?
c. (This is more of a RevDCM question). My mod is built on top of other modcomps including RevDCM. A number of functions in CvGameUtils.py are modified by the RevDCM team and *not* further modified by me. I assume that I should just delete these functions from my MyModGameUtils.py file, because RevDCM has also updated to use this new BUG. True?
d. On the other hand, if there is some other small python modcomp which I have incorporated into my mod, I should probably keep their functions in MyModGameUtils. Or, at least find out if they have updated to BUG and get their files if so. True?
e. Suppose I have overridden five of the CvGameUtil functions and I want to use the default functions for the rest, and also my class contains many extra functions. How does BUG decide what to do? Does it search all the function names in my mod for matches with the default functions? Or do I have to give more information about which functions to use?