Any way of detecting current game month?

I haven't checked this: what is returned by CyGameTextMgr.getDateStr(INT iGameTurn, BOOL bSave, CalendarType eCalendar, INT iStartYear, GameSpeedType eSpeed)?
Ok, I checked and it returned this (with bSave=False):
PHP:
"October 2019 AD"
So all I need to do is parse this string if I need to lookup the date/month... :rolleyes:

edit: I guess I could do it this way:
Code:
import string
date = CyGameTextMgr().getDateStr(iGameTurn, False, eCalendar, iStaringYear, eSpeed)
lDate = string.split(date)
month = lDate[0]
eMonth = eval("MonthTypes.MONTH_" + string.upper(month))
Right?
 
split() and upper() are both methods of the string class, so you don't need to import anything. Also, if you can assume the format you posted will always be the case, you can shorten it. Finally, instead of eval() you can look up the value using getattr(). It's a very handy feature of Python.

Code:
try:
    date = CyGameTextMgr().getDateStr(iGameTurn, False, eCalendar, iStaringYear, eSpeed)
    month, year, bcad = date.split()
    eMonth = getattr(MonthTypes, "MONTH_" + month.upper())
except:
    eMonth = MonthTypes.MONTH_JANUARY

The way that all enumeration classes are defined in Civ4, all values are attributes of the class. And you can access these attributes using a simple dictionary lookup. getattr() is a nice way to do the lookup. And a little error-handling doesn't hurt. ;)
 
Very nice...
 
heyis, related to this...

I need a simple piece of python, for a random event.

I have a start event, then a follow on event 5 turns later, that I need to recur every 5 turns forever.

currently I have this:

Code:
def canDoElectionDone1(argsList):
	iEvent = argsList[0]
	kTriggeredData = argsList[1]
	player = gc.getPlayer(kTriggeredData.ePlayer)
	
	if gc.getGame().getGameTurn() >= kTriggeredData.iTurn + 5:
		return true
				
	return false

Not working though - what am I doing wrong?

HDK
 
Firstly, use
Code:
 tags when posting code. Your indentation isn't showing, making it impossible to verify your code.

Secondly, the only thing  preventing this from working would probably be an unrelated Python exception, throwing all Python out the window for the particular game event callup. Have you enabled Python exceptions?
 
Firstly, use
Code:
 tags when posting code. Your indentation isn't showing, making it impossible to verify your code.

Secondly, the only thing  preventing this from working would probably be an unrelated Python exception, throwing all Python out the window for the particular game event callup. Have you enabled Python exceptions?[/QUOTE]

Thank you - done,a s above.

Re exceptions - i'm still a beginner level with python. I'm working solely within the RandomEventsInterface.py. I have not touched any other python code, or inserted any code. Thence I doubt I have enable exceptions.

I want the event to fire when I switch to Representation, and to fire every 5 turns after that. From Solvers guide I'm pretty certain I have the xml code fine - ive been random event modding for a long while, but only recently delving into python.

I'm stumped on this. The event fires ONCE, when I switch to Rep, but does not repeat. If the code above is fine then its possible i have something in XML cancelling out the repeat. I will double check.

HDK
 
Where is the function call for canDoElectionDone1() coming from?
 
Where is the function call for canDoElectionDone1() coming from?

Ah; Im working within the random event system.

This consists of:

xml file - random event trigger
xml file - the event itself
py file - python script that can be called by either the event trigger or the event itself.

In my case, I want the trigger to use a py script to see if it can fire.

Instead of relkying on a specific number of turns, could Instead have it checkevery tenth turn? eg, turn 10, 20, 30, etc?

Then, if all the other conditions are met it fires, the trigger fires, the event fires and I get my election.
 
I guess what I'm curious about is what other functions you have defined. Is there a canDoElectionDone() or perhaps a canDoElectionDone2()?

I didn't read the OP properly. The way to have intervals with Python, or any programming language for that matter, is to use a modulus operation. So what you need is probably:
Code:
iGameTurn = gc.getGame().getGameTurn()
if iGameTurn % 5 == 0 and iGameTurn >= kTriggeredData.iTurn:
    return True
Because % 5 will only be equal to zero every fifth turn. Note however that this doesn't actually count 5 turns from the original date (kTriggeredData.iTurn) but rather fires on every game turn equally dividable by 5.

To have the function return True the first time 5 turns from would then be achieved with something like:
Code:
iModulo =  kTriggeredData.iTurn % 5
iGameTurn = gc.getGame().getGameTurn()
if iGameTurn % 5 == iModulo and iGameTurn > kTriggeredData.iTurn:
    return True
Regarding Python exceptions; you need to enable these in the Civilization4.ini file found in the MyGames\Beyond the Sword\ folder. The actual error logs are found in the Logs subfolder.

And welcome to the community of Python modders. :king:
 
Top Bottom