pass info to pop-up?

Lutefisk Mafia

Inscrutable Enforcer
Joined
Jun 15, 2007
Messages
544
Location
Minnesota
I have a python generated popup message that pops up when a unit qualifies for a certain status on a doTurn() iteration.

How might I pass the name of the unit to the TXT entry for the popup?

I think that I can grab the name by using a pUnit.getName() function, but don't know how to get my popup text to use this.

Anyone know how this is done?

Thanks!
 
Would have to see the code really to say precisely how to handle it, but I assume this is all in python? If so, after your "TXT_KEY_BLAHBLAH" you have a , (), you can place data in the () which is then useable in the TXT_KEY as %s, %d, %D or whatever.

So the trick here would be that either you are building the popup IN doTurn(), so the variable should be handy to use right away, or you are calling a function FROM doTurn(), in which case if the function is JUST for building your popup, you'll add a variable to pass into the function.
 
Here is the base code:

Code:
cf.addPlayerPopup(CyTranslator().getText("TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR",()), iPlayer)

appears as a line in the onTurn(self): function

and the TXT entry looks like this:

Code:
    <TEXT>
        <Tag>TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR</Tag>
        <English>You found a secret door!</English>
        <French>Add text</French>
        <German>Add text</German>
        <Italian>Add text</Italian>
        <Spanish>Add text</Spanish>
    </TEXT>

This works fine. But I want to take a PUnit.getName() string pulled from a pUnit that appears earlier in the loop that leads up to the popup -- and add it as a part of the popup.

So right now the popup box just contains:

You found a secret door!

I want it to add the name of the unit that found it, so it would look like:

Spongebob (Myconid) found a secret door!
 
Code:
cf.addPlayerPopup(CyTranslator().getText("TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR",([COLOR="DeepSkyBlue"]pUnit.getName()[/COLOR])), iPlayer)


Code:
    <TEXT>
        <Tag>TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR</Tag>
        <English>[COLOR="#00bfff"]%s [/COLOR]found a secret door!</English>
        <French>Add text</French>
        <German>Add text</German>
        <Italian>Add text</Italian>
        <Spanish>Add text</Spanish>
    </TEXT>
 
If I put a %s in the TXT field it actually shows up as "%s" no matter what.

If I put a %s1, like I see in other TXT entries, it shows up as "???" in the popup message.

But no matter what I put in the python popup call, it causes errors that make the entire mechanism not work.

Here is what is in doTurn:

Code:
		iPlayer = 0 #Kandros
		pPlayer = gc.getPlayer(iPlayer)
		py = PyPlayer(iPlayer)
		for pUnit in py.getUnitList():
			iX = pUnit.getX()
			iY = pUnit.getY()
			for iiX in range(iX-1, iX+2, 1):
				for iiY in range(iY-1, iY+2, 1):
					p2Plot = CyMap().plot(iiX,iiY)
					for i in range(p2Plot.getNumUnits()):
						p2Unit = p2Plot.getUnit(i)
						if p2Unit.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE') and p2Plot.getFeatureType() == gc.getInfoTypeForString('FEATURE_WALLS'):
							p2Unit.kill(False,0)
							p2Plot.setFeatureType(-1, -1)
							cf.addPlayerPopup(CyTranslator().getText("TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR", (pUnit.getName())), iPlayer)

what am I missing here?

The code is supposed to look at all of the player's units when it advances to the next turn (this is okay -- it is a scenario and there will never be very many units).

For each unit, it looks at the adjacent plots. If any of those plots contains both Walls and a Slave unit, the Slave is killed, the Wall disappears, and the popup triggers. (I am using Slaves in a special way instead of warning posts and jungle altars, which I can't stand.)

This mechanism works -- I have tested it extensively. But I just want to pass the name of the unit that triggered the secret door to the text of the Popup message. I have messed around with this for over an hour and a half, trying different permutations and it is driving me nuts.

Any insight you can offer would be welcome.
 
If I put a %s in the TXT field it actually shows up as "%s" no matter what.

If I put a %s1, like I see in other TXT entries, it shows up as "???" in the popup message.

The %s1 is correct. I do this all the time in XML as when doing the same thing in Python, you don't put the numbers after the %s, %d, et al codes.

The one thing missing is that you need a , to force the second parameter to getText() to be a tuple rather than a single value:

Code:
cf.addPlayerPopup(CyTranslator().getText("TXT_KEY_EVENT_WB_DUNGEON_ADVENTURE_FOUND_SECRET_DOOR", (pUnit.getName()[B][COLOR="YellowGreen"],[/COLOR][/B])), iPlayer)

To make sure you can spot it, the comma goes after the getName() call:

Code:
. . . (pUnit.getName()[B][COLOR="YellowGreen"],[/COLOR][/B]) . . .

Python needs this whenever a tuple contains a single element.
 
Thank you! That little comma was all that was missing! :goodjob:

These functions now work perfectly, and I think that they will add quite a bit of flavor to the scenario I am working on.

Once, again, thanks to you both for the advice.

Cheers! :)
 
Top Bottom