Adding additional python files to a mod

Zechnophobe

Strategy Lich
Joined
Sep 1, 2006
Messages
1,867
Location
Goleta, California
I'm making a mod, and want to put functions, and functionality, in seperate files from those python files currently located in the game. For instance, a file of ScenarioFunctions that are specific to the mod I'm working on.

I'm not incredibly fluent in python yet, so I'm constantly worried that is where I've made mistake.

Code:
from CvPythonExtensions import *
import CvUtil
import Popup as PyPopup
import PyHelpers
import CvScreenEnums

gc = CyGlobalContext()

class ScenarioFunctions:

This is how I've startded off the file, and I believe it should be accessible from other files by

import ScenarioFunctions

and perhaps doing something akin to

sf = ScenarioFunctions.ScenarioFunctions()

which I've seen in other code, and I'm assuming that calls a default constructor of the class to get a reference to a new one.


Problem is, any of the py files I even import my new class into stop working. What am I doing wrong?
 
Do you have python exceptions turned on?

The only kink I know of with importing files is, you can't import FileA into FileB and then import FileB into FileA, this will cause a recursive loop.

Except for that, you can put any .py file in any directory under /Mods/<OurMod>/Assets/Python and it will be accessable with the import statement in any other python file in that mod.
 
Where would one do this?

Open your CivilizationIV.ini file.

Find this:
; Set to 1 for no python exception popups
HidePythonExceptions = 1

And change it to this:
; Set to 1 for no python exception popups
HidePythonExceptions = 0

There should be a shortcut to the CivilizationIV.ini file in your game folder.
 
Look in \My Documents\My Games\Beyond the Sword\, the CivilizationIV.ini file.

Look for
Code:
; Set to 1 for no python exception popups
HidePythonExceptions = 1

and make sure it looks like
Code:
; Set to 1 for no python exception popups
HidePythonExceptions = 0

This make sure that when python runs into a problem it will tell you about it.

You may also want to look through the rest of the CivilizationIV.ini file and turn on the logging options. This will put all kinds of logging files in the My Documents\My Games\Beyond the Sword\Logs directory. They are kinda cryptic, but the PythonErr.log and PythonErr2.log will have the python exceptions in a more readable format then the popups give you in the game.
 
Back
Top Bottom