Double messages - problems with a mod comp

The_J

Say No 2 Net Validations
Administrator
Supporter
Joined
Oct 22, 2008
Messages
42,141
Location
DE/NL/FR
I have at the moment a problem with one of my modcomps, or more with a merge of it.

Smeagolheart tries to merge one of my modcomps (this) into his mod.
The mod comp should add messages to the game, when a city with a wonder is conquered, and which wonders are conquered (or if the city is razed, which are destroyed.

Code:
Spoiler :

PHP:
	def onCityAcquiredAndKept(self, argsList):
		'City Acquired and Kept'
		iOwner,pCity = argsList
#### messages - wonder captured start ####		
		NumWonders = pCity.getNumWorldWonders
		if NumWonders ()>0:
                        Counter = 0
                        for i in range(gc.getNumBuildingInfos ()):
                                thisbuilding = gc.getBuildingInfo (i)
                                if pCity.getNumBuilding(i)>0:
                                        iBuildingClass = thisbuilding.getBuildingClassType ()
                                        thisbuildingclass = gc.getBuildingClassInfo (iBuildingClass)
                                        if thisbuildingclass.getMaxGlobalInstances ()==1:
                                                ConquerPlayer = gc.getPlayer(pCity.getOwner())
                                                iConquerTeam = ConquerPlayer.getTeam()
                                                ConquerName = ConquerPlayer.getName ()
                                                WonderName = thisbuilding.getDescription ()
                                                iX = pCity.getX()
                                                iY = pCity.getY()
                                                for iPlayer in range (gc.getMAX_CIV_PLAYERS ()):
                                                        ThisPlayer = gc.getPlayer(iPlayer)
                                                        iThisTeam = ThisPlayer.getTeam()
                                                        ThisTeam = gc.getTeam(iThisTeam)
                                                        if ThisTeam.isHasMet(iConquerTeam):
                                                                if iPlayer == pCity.getOwner():
                                                                        CyInterface().addMessage(iPlayer,False,15,CyTranslator().getText("TXT_KEY_YOU_CAPTURED_WONDER",(ConquerName,WonderName)),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(gc.getInfoTypeForString("COLOR_GREEN")), iX, iY, True,True)
                                                                else:
                                                                        CyInterface().addMessage(iPlayer,False,15,CyTranslator().getText("TXT_KEY_CAPTURED_WONDER",(ConquerName,WonderName)),'',0,'Art/Interface/Buttons/General/warning_popup.dds',ColorTypes(gc.getInfoTypeForString("COLOR_RED")), iX, iY, True,True)
#### messages - wonder captured end ####

There's nearly the same code after onCityRazed.


Now, smeagolheart gets every message twice, and with some additional debugging messages, i've nailed the problem down to this here:
PHP:
                                            if ThisTeam.isHasMet(iConquerTeam):
                                                                                                        CyInterface().addMessage(0,False,15,CyTranslator().getText("passed has met check",()),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(gc.getInfoTypeForString("COLOR_GREEN")), iX, iY, True,True)
                                                                                                        print "passed has met check: iPlayer = "+str(iPlayer)
                                                    if iPlayer == pCity.getOwner():
                                                            CyInterface().addMessage(iPlayer,False,15,CyTranslator().getText("TXT_KEY_YOU_CAPTURED_WONDER",(ConquerName,WonderName)),'',0,'Art/Interface/Buttons/General/happy_person.dds',ColorTypes(gc.getInfoTypeForString("COLOR_GREEN")), iX, iY, True,True)                                                                    
                                                    else:
                                                            CyInterface().addMessage(iPlayer,False,15,CyTranslator().getText("TXT_KEY_CAPTURED_WONDER",(ConquerName,WonderName)),'',0,'Art/Interface/Buttons/General/warning_popup.dds',ColorTypes(gc.getInfoTypeForString("COLOR_RED")), iX, iY, True,True)
#### messages - wonder captured end ####

The logs say, that in the example case the "if ThisTeam.isHasMet" check is passed two times, for player #0 and #6. But the messages still appear twice for the human player (#0, i assume).
I could add more messages, but...well...this is just a simple if then else check, i don't see what could be going wrong here (to note: No teams involved, which could be a reason for a bug, i know).


So does anyone see, how here could be a problem?
I must be incredibly stupid, i can't see it :crazyeye:.
 
Whats up with line 2-3 in the second except? (I can't see those lines in the first one, and the indentation is waaay to the right. It doesn't seem to be tabs either...)
 
I thought the whole purpose of this thread was that the file didn't work... But whatever.
 
Of course its not possible so it must be something completely different then.

I actually experienced such an "echo" myself yesterday, about the same time I read the OP. I have no idea what caused it though... My guess its the interface itself and not the actual Python. But I really have no clue... :dunno: It will be interesting to find out what caused it, in any case. :p
 
I looked at the code again and it dawned on me that the onCityAcquiredAndKept callup could be done more than once? This would cause the message to also fire more than once, right?

Are there duplicate Event Managers/Handlers or whatever involved? Or something to do with how CyInterface handles messaging. Any weird thing is possible if we're dealing with someone who is just "merging" stuff without understanding the what, where and why...

Because this particular mod component only misbehaves within this particular context, right? Then there is nothing wrong with the code as such. (Well, I sure can't spot it if there is. But then again it can be hard to do so.)
 
The code is "only" attached to onCityAcquired and onCityRazed, and these events should not be called more than once.

Yes, the problem is in a merge, with a custom eventmanager in BUG, but EF said, that there can't really be an interaction.
And even then: All the other debugging messages before only appear once. If it really was called twice, i would get twice the messages.

And yes, at itself, the component works, it's only a problem in that merge.
 
So something must me messing up CyInterface or whatever is responsible for the messaging then. Because its repeating itself.

My own "echo" was created by CyGameTextMgr by the way... But I don't know how.
 
The code is "only" attached to onCityAcquired and onCityRazed, and these events should not be called more than once.

"Should not be", I agree. Suppose I accidentally write this in init.xml:

Code:
<gameutils module="mymod" handler="onCityAcquired"/>
<gameutils module="mymod" handler="onCityAcquired"/>

Wouldn't that cause all the messages from this handler to be printed twice, because the function itself is called twice?
 
Yeah, this is the sort of thing I was also suspecting. But somewhere like in CvEventInterface or whatever is higher up in hierarchy from the actual CvEventHandler. Basically a double call.

edit: But then all the code should run twice, right? And its not. Is there any C++ in this mod? Perhaps its not Python related at all, but inherited from the DLL.
 
"Should not be", I agree. Suppose I accidentally write this in init.xml:

Code:
<gameutils module="mymod" handler="onCityAcquired"/>
<gameutils module="mymod" handler="onCityAcquired"/>

Wouldn't that cause all the messages from this handler to be printed twice, because the function itself is called twice?

I would think so, that's how i understand it.

Yeah, this is the sort of thing I was also suspecting. But somewhere like in CvEventInterface or whatever is higher up in hierarchy from the actual CvEventHandler. Basically a double call.

edit: But then all the code should run twice, right? And its not. Is there any C++ in this mod? Perhaps its not Python related at all, but inherited from the DLL.

If there's a custom dll in, then probably not really custom (BBAI, or so).
 
Which message does the human player see twice? Is it the same message (you have captured...) or one of each message?
 
Okay, let's go over the basics then. Where is this event handler defined? Is it a module-level function or in a class? How are you registering it with BUG? I need to see actual code and XML here.
 
Did anyone ever figure out what the problem was?

Because I just realized that the double-prints I'm getting in the console are caused by Unicode strings. I don't know if this is related somehow to what you guys were experiencing, but the game perhaps gets confused with Unicode versus regular string types?
 
Maybe timing? I had also "echoes" of messages. Not always, but always of the same type.

"nomads&rebels" uses onCityGrowth & onCultureExpansion to set a flag.
If onEndGameTurn checks this flag (same turn) and generates a message. echoes.
If onEndPlayerTurn checks this flag (next turn!) and generates a message. ok

In principle, details IIRC.
 
Because I just realized that the double-prints I'm getting in the console are caused by Unicode strings.

I had wondered what caused that in the console. They don't appear doubled in the log. And the strings I was printing didn't contain any Unicode-specific characters, but they were Unicode strings in Python.

I don't think that would relate to the event messages though since those go through CyInterface instead of the console.
 
Back
Top Bottom