Bad Player
Deity
Hi, I've been working on this code with the help of some other ppl but we can't work out why the program crashes on turn 9. I've run the program a few times and every time it crashes on turn 9. I use worldbuilder to place a few units and move them into tile (10,10) where they get the HELD promotion (so they can't move) and the program teleports them N/S/W/NW/NE (except once it moved them SE to avoid opponent borders which was unexpected).
CvEventManager (in FFH2/MNAI):
The error messages are:
KeyError: 0
Line 567 CvEventManager (which is iOldX = myPickle[0])
BugEventManager line 361
Traceback (most recent call last)
CvEventManager (in FFH2/MNAI):
Code:
#NEW CODE STARTS HERE
#This code should give all units in tile(10,10) the HELD promotion so that they can't move anywhere.
if iGameTurn < 5:
pPlot = CyMap().plot(10,10)
for i in range(pPlot.getNumUnits()):
pUnit = pPlot.getUnit(i)
pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), True)
#pUnit.setScriptData("StackofDoom")
#This should teleport all units in the tile to an adjacent clear tile not east of the tile
if iGameTurn == 5:
pPlot = CyMap().plot(10,10)
pPlotWest = cf.findWestClearPlot(-1, pPlot)
#save new data to the actual game file
iNewX = pPlotWest.getX()
iNewY = pPlotWest.getY()
myPickle = [iNewX, iNewY]
serializedMyPickle = pickle.dumps(myPickle)
gc.getGame().setScriptData(serializedMyPickle)
#apply new data on units
for i in range(pPlot.getNumUnits(), -1, -1):
pUnit = pPlot.getUnit(i)
pUnit.setXY(iNewX, iNewY, False, True, True)
if iGameTurn > 5:
if iGameTurn <=12:
# get old data from the actual game file
serializedMyPickle = gc.getGame().getScriptData()
myPickle = pickle.loads(serializedMyPickle)
iOldX = myPickle[0]
iOldY = myPickle[1]
pPlot = CyMap().plot(iOldX, iOldY)
pPlotWest = cf.findWestClearPlot(-1, pPlot)
#save new data to the actual game file
iNewX = pPlotWest.getX()
iNewY = pPlotWest.getY()
myPickle = [iNewX, iNewY]
serializedMyPickle = pickle.dumps(myPickle)
gc.getGame().setScriptData(serializedMyPickle)
#apply new data on units
for i in range(pPlot.getNumUnits(), -1, -1):
pUnit = pPlot.getUnit(i)
pUnit.setXY(iNewX, iNewY, False, True, True)
The error messages are:
KeyError: 0
Line 567 CvEventManager (which is iOldX = myPickle[0])
BugEventManager line 361
Traceback (most recent call last)