Possible to keep track of events that occur?

deanej

Deity
Joined
Apr 8, 2006
Messages
4,859
Location
New York State
For a scenario that I'm making, I have events that occur when a specific unit enters specific plots on the map. I have the code that identifies the unit/plots, but I also need to keep track of what events have/have not occurred and when. This is so that events don't occur twice in the game and also because a couple of events have follow-up events that occur after a certain amount of turns after the original event. However, the game does not recognize the variables that I use to keep track of the events. In onGameStart:

Code:
		b01 = False
                b02 = False
                b06 = False
                b07 = False
                b13 = False
                b18 = False
                b20 = False
                b22 = False
                b24 = False
                iShipment = 500
                iCouncil = 500

In onBeginPlayerTurn:
Code:
#Detect Enterprise
		iEpisodeID = 0
		i3x01 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_01')
		i3x02 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_02')
		i3x06 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_06')
		i3x07 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_07')
		i3x13 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_13')
		i3x18 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_18')
		i3x20 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_20')
		i3x22 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_22')
		i3x24 = CvUtil.findInfoTypeNum(gc.getFeatureInfo,gc.getNumFeatureInfos(),'FEATURE_24')
		for iPlotLoop in range(CyMap().numPlots()):
                    pPlot = CyMap().plotByIndex(iPlotLoop)

                    for c in range(pPlot.getNumUnits()):
                        pUnit = pPlot.getUnit(c)
                        if (pUnit.getOwner() == 0):
                            if (pPlot.getFeatureType() == i3x01):
                                iEpisodeID = 1
                            elif (pPlot.getFeatureType() == i3x02):
                                iEpisodeID = 2
                            elif (pPlot.getFeatureType() == i3x06):
                                iEpisodeID = 6
                            elif (pPlot.getFeatureType() == i3x07):
                                iEpisodeID = 7
                            elif (pPlot.getFeatureType() == i3x13):
                                iEpisodeID = 13
                            elif (pPlot.getFeatureType() == i3x18):
                                iEpisodeID = 18
                            elif (pPlot.getFeatureType() == i3x20):
                                iEpisodeID = 20
                            elif (pPlot.getFeatureType() == i3x22):
                                iEpisodeID = 22
                            elif (pPlot.getFeatureType() == i3x24):
                                iEpisodeID = 24

		#Do Events if needed
		if (iEpisodeID == 1 and not b01):
                    self.doXindi()
                elif (iEpisodeID == 2 and not b02):
                    self.doAnomaly()
                elif (iEpisodeID == 6 and not b06):
                    self.doExile()
                elif (iEpisodeID == 7 and not b07):
                    self.doShipment()
                elif (iEpisodeID == 13 and not b13):
                    self.doProvingGround()
                elif (iEpisodeID == 18 and not b18):
                    self.doAzatiPrime()
                elif (iEpisodeID == 20 and not b20):
                    self.doForgotten()
                elif (iEpisodeID == 22 and not b22):
                    self.doCouncil()
                elif (iEpisodeID == 24 and not b24):
                    self.doZeroHour()

                #Do Proving Ground and Countdown
                iKema = iShipment + 3
                iCountdown = iCouncil + 3
                if (iGameTurn == iKema):
                    self.doKemacite()
                elif (iGameTurn == iCountdown):
                    self.doCountdown()

I get the following python exception:
Spoiler :
Traceback (most recent call last):

File "CvEventInterface", line 19, in onEvent

File "CvEventManager", line 187, in handleEvent

File "CvFinalFrontierEvents", line 355, in onBeginGameTurn

NameError: global name 'iShipment' is not defined
ERR: Python function onEvent failed, module CvEventInterface


Debug code that I had in there before I changed the code countless times in an attempt to make the game see the variables revealed that the game is assigning the variable, but it somehow forgets it when onBeginGameTurn is callled. Putting the variables outside the class does not work either. The only thing that does work is putting them in onBeginGameTurn, but I can't have it that way because then they will all get reset every turn, defeating the purpose. I get this error for the other variables as well, but only when the unit is on the plot in question. Please help.
 
To keep track of some kind of variable you want to use ScriptData. City, Game, Player, Plot, and Unit objects all have getScriptData/setScriptData methods for storing and retrieving data associated with them. The data stored is actually just a string, but you can use something like sdToolKit to easily work with complex types.
 
Back
Top Bottom