[Python] Problem with lists in EventManager

fktest

Chieftain
Joined
Mar 19, 2007
Messages
3
Hi,

I am currently trying to add a little modification (stealing techs when capturing cities). I figured that the right place to do that is probably the onCityAcquired hook in CvEventManager.py.

First I get the player/team of the previous and the new owner
Code:
newOwner = gc.getPlayer(iNewOwner)
newTeam = gc.getTeam(newOwner.getTeam())
previousOwner = gc.getPlayer(iPreviousOwner)
previousTeam = gc.getTeam(previousOwner.getTeam())

then I try to create a list with techs that might possibly be stolen

Code:
# create a list with all techs owned by previous but not by current player
possibleTechs= [i for i in range(gc.getNumTechInfos() if previousTeam.isHasTech(i) and not newTeam.isHasTech(i)]

Unfortunately, the latter doesn't seem to work, the method doesn't finish anymore (I added a little popup add the end to see that).

I also tried using more conventional code style:

Code:
possibleTechs = []
for i in range(gc.getNumTechInfos()):
  if (previousTeam.isHasTech(i) and not newTeam.isHasTech(i)):
    possibleTechs.append(i)

but no success either. But I noticed another odd thing: I can use append outside the for loop, but not inside.
Since I don't know a great deal about pyhton and it's variable scopes and so on, I created a similar test-class outside of civ where I did a similar thing an it worked instantly...
I would really appreciate any help on this... is it a general python issue or some civ-specific thing? Sorry for posting such a lengthy question and thanks in advance!

greetings,
jonas
 
At first glance that looks right to me. Can you post the error that you're getting? It will be located in Logs/PythonErr.log as a stack trace (the function calls in order leading up to the error, plus the error itself). It will point out the file and line number containing the problem.

If that file doesn't exist or is blank, you need to turn on logging in CivilizationIV.ini:

Code:
; Enable the logging system
LoggingEnabled = 1
 
Hello,

thank you for pointing me to the log file, this was very helpful. I was getting syntax errors at very strange locations. Appearantly my editor messed up the whitespace, so it looked right although it wasn't ... and since whitespace is so important (I can't believe how stupid that is!) to python... Now I'm not getting any errors anymore, so this can probably be closed or deleted!

Giving the attacker the first tech would be simpler, but that's a little too simple I think ;)

Thanks for your help!

Greetings
jonas
 
The old whitespace problem kinda sucks, but if you get in the habit of only using tabs (or set your editor to do that) it goes away.
 
Top Bottom