RogerBacon
Jan 25, 2006, 07:02 PM
I'm trying to use the DataStorage class Bhruic made and I'm having a bit of trouble.
I want to store three values for a city: the gold, research and culture generated by specialists each turn. Basically, I'm doing something to add to it each turn. The problem is that I want to add 2 each turn but using City.changeSpecialistCommerce() is cumulative. i.e. 2, 4, 6, etc. So, I decided to store last turn's bonus, add the new bonus (which might be the same) minus last turn's bonus. So, I did this:
iRandNum = gc.getGame().getMapRand().get(3, "Type of commerce") # gold, science, culture
lastTurnBonusCommerce = data.getVal('Workers', pCity.getID(), iRandNum, pCity)
...
bonusCommerce += pUnit.getLevel()
...
pCity.changeSpecialistCommerce(iRandNum, bonusCommerce - lastTurnBonusCommerce )
specialistCommerce = pCity.getSpecialistCommerce(iRandNum)
data.setVal('Workers', pCity.getID(), iRandNum, specialistCommerce , pCity)
Unfortunately, I'm not using the dataStorage class correctly, I guess. For one thing, I don't exactly understand what pEntity is supposed to be. Does anyone have any examples where they have used these functions of this class?
The error I get is:
File "DataStorage", line 78, in getVal
KeyError: 1
1 in this case means that 'science' was chosen as the random commerce type to get the bonus that turn. If I get rid of the random element it seems to work fine.
Thanks,
Roger Bacon
I want to store three values for a city: the gold, research and culture generated by specialists each turn. Basically, I'm doing something to add to it each turn. The problem is that I want to add 2 each turn but using City.changeSpecialistCommerce() is cumulative. i.e. 2, 4, 6, etc. So, I decided to store last turn's bonus, add the new bonus (which might be the same) minus last turn's bonus. So, I did this:
iRandNum = gc.getGame().getMapRand().get(3, "Type of commerce") # gold, science, culture
lastTurnBonusCommerce = data.getVal('Workers', pCity.getID(), iRandNum, pCity)
...
bonusCommerce += pUnit.getLevel()
...
pCity.changeSpecialistCommerce(iRandNum, bonusCommerce - lastTurnBonusCommerce )
specialistCommerce = pCity.getSpecialistCommerce(iRandNum)
data.setVal('Workers', pCity.getID(), iRandNum, specialistCommerce , pCity)
Unfortunately, I'm not using the dataStorage class correctly, I guess. For one thing, I don't exactly understand what pEntity is supposed to be. Does anyone have any examples where they have used these functions of this class?
The error I get is:
File "DataStorage", line 78, in getVal
KeyError: 1
1 in this case means that 'science' was chosen as the random commerce type to get the bonus that turn. If I get rid of the random element it seems to work fine.
Thanks,
Roger Bacon