EmperorFool
Deity
You code must also be storing a list into an object's script data that DynamicUnitNames (not a part of BUG) is using because that's the code that is getting the error. It is expecting a dictionary because it uses SdToolkit.
Then these separate ways of storing data shouldn't be conflicting, as far as I can see...
You code must also be storing a list into an object's script data that DynamicUnitNames (not a part of BUG) is using because that's the code that is getting the error. It is expecting a dictionary because it uses SdToolkit.
I've been thinking about what you said above and it has taken awhile to sink in.Global variables and functions in one module are available to any other module that imports it by placing the module's name in front.
def __init__(self, scriptDict):
global scriptDict
These things might not be very obvious...Ok now I'm really wondering what's up. I thought, as everyone was thinking, that the error I was getting had something to do with the mod saving data and that was somehow conflicting with dynamiccivnames.
You really need to post all exceptions here so that we can locate the error.Now I'm not so sure, I've gone through the code and removed all lines that save scriptdata and replaced them with calls to the sdtoolkit. I even blanked out the whole onbegingameturn function so it's just an empty nothing and still I get an error onbeginplayerturn from dynamiccivnames. Wth?
pass
These things might not be very obvious...
You really need to post all exceptions here so that we can locate the error.
Like if you "blank out" the contents of a function (the body) you would probably get a syntax error or something like that. Because there is no such thing as a non-body of a function. If you wanna replace it with a non-statement, you use:
Its sort of a place-holder statement.Code:pass
Without knowing what you've done exactly, an empty body should result in an exception - on initialization or whenever the Python is reloaded. Otherwise I'd suspect that module isn't even being used! (It won't load if it isn't imported by another module to begin with.)There was no other exception other than the one I've already posted. It doesn't show up until I end the turn. It didin't give an error without 'pass'
Yeah, the point of storing scriptData is that it gets saved along with the save game. Like in the CyGame, CyPlayer or CyPlot instance. But having scriptData present that isn't used any more can't hurt either - supposing you've commented out all the code that is accessing it.I think now the problem was I was loading a savegame and testing the python, it had perhaps the corrupt data saved with it
# psuedocode
game = CyGame()
data = unpickle(game.getScriptData())
if type(data) == 'list':
newData = dict()
newData['myData'] = data
game.setScriptData(pickle(newData))
SdToolkit and BugData require a dictionary as the root structure of the script data. They store dictionaries in that big dictionary, keyed by the mod ID with which they are initialized. By storing a list there, you mess up SdToolkit.
Best if you can start a new game. Do you have to load that saved game?
def initScriptData(self):
iZero = 0
aScriptData = [iZero]
# Initialize PlagueData
self.msg("Initializing PlagueData.")
if( not SDTK.sdObjectExists( "PlagueData", gc.getGame() ) ) :
SDTK.sdObjectInit( "PlagueData", gc.getGame(), {} )
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueBool", aScriptData )
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueCoords", aScriptData )
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueCounter", aScriptData )
elif( SDTK.sdObjectGetVal("PlagueData", gc.getGame(), "PlagueBool") == None ) :
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueBool", aScriptData )
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueCoords", aScriptData )
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueCounter", aScriptData )
def setPlagueState(self, iValue):
aszScriptData = SDTK.sdObjectGetVal("PlagueData", gc.getGame(), "PlagueBool")
aszScriptData[0] = iValue
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueBool", aszScriptData )
Good for you!I'm attempting to rewrite all data storage calls from scratch currently.
Once again: What is the exception?This the code that worked fine once, then quit, start new game to test somethign else and it throws the exception.
Traceback (most recent call last):
File "BugEventManager", line 361, in _handleDefaultEvent
File "GreatDoctorEventManager", line 59, in onModNetMessage
File "GreatDoctorEventManager", line 217, in doEventPlague
File "GreatDoctorEventManager", line 331, in setPlagueCounter
TypeError: object does not support item assignment
@Baldyr, love the new Lena updates.
TypeError: object does not support item assignment
def setPlagueCounter(self, iValue):
aszScriptData = SDTK.sdObjectGetVal("PlagueData", gc.getGame(), "PlagueCounter")
[COLOR="Red"]aszScriptData[0] = iValue[/COLOR]
SDTK.sdObjectSetVal( "PlagueData", gc.getGame(), "PlagueCounter", aszScriptData )
aszScriptData["PlagueData"] = iValue
import BugData
import BugUtil
BugUtil.fixSets(globals())
...
def getCounter(self):
table = BugData.getTable("Plague")
if "counter" in table:
return table["counter"]
else:
return 0
def setCounter(self, iValue):
table = BugData.getTable("Plague")
table["counter"] = iValue
def isCityInfected(self, pCity):
# the "cities" table contains a single set object "coords"
# that contains (x,y) points
table = BugData.findTable("Plague", "cities")
if table:
point = (pCity.getX(), pCity.getY())
return point in table["coords"]
return False
def infectCity(self, pCity):
table = BugData.getTable("Plague", "cities")
point = (pCity.getX(), pCity.getY())
if "coords" not in table:
table["coords"] = set()
table["coords"].add(point)
def setPlague(self, pTurns, pCoords):
table = BugData.getTable("Plague")
table["counter"] = pTurns
table["city"] = pCoords