[Python/SDK] Game doesn't recognize new CyGameTextMgr function I added

Maniac

Apolyton Sage
Joined
Nov 27, 2004
Messages
5,596
Location
Gent, Belgium
I needed to make some changes to the F7 religion screen, which didn't really fit into the existing getReligionHelpCity function, so I added a new function myself.

Alas, there is some problem. When I open the F7 screen, I get the python exception message:

'CyGameTextMgr' object has no attribute 'getReligionHelpScreen'

I have no idea what could be causing this. The non-CvGameTextMgr.cpp part of the code for getReligionHelpScreen is pretty much copied-and-pasted from getReligionHelpCity, so I don't understand where the problem could lie. Anyone an idea?

For the record I posted my getReligionHelpScreen and the original getReligionHelpCity code here for comparison:

getReligionHelpScreen:

CvReligionScreen.py

szCityName += CyGameTextMgr().getReligionHelpScreen(iLinkReligion, pLoopCity.GetCy())

CyGameTextMgr.h

std::wstring getReligionHelpScreen(int iReligion, CyCity* pCity);

CyGameTextMgr.cpp

Code:
std::wstring CyGameTextMgr::getReligionHelpScreen(int iReligion, CyCity* pCity)
{
	CvWStringBuffer szBuffer;
	GAMETEXT.setReligionHelpScreen(szBuffer, (ReligionTypes)iReligion, ((pCity != NULL) ? pCity->getCity() : NULL));
	return szBuffer.getCString();
}


getReligionHelpCity

CvReligionScreen.py

Code:
			if (iLinkReligion == -1):
				bFirst = True
				for iI in range(len(lReligions)):
					szTempBuffer = CyGameTextMgr().getReligionHelpCity(lReligions[iI], pLoopCity.GetCy(), False, False, False, True)
					if (szTempBuffer):
						if (not bFirst):
							szCityName += u", "
						szCityName += szTempBuffer
						bFirst = False
			else:
				szCityName += CyGameTextMgr().getReligionHelpCity(iLinkReligion, pLoopCity.GetCy(), False, False, True, False)

CyGameTextMgr.h

std::wstring getReligionHelpCity(int iReligion, CyCity* pCity, bool bCityScreen, bool bForceReligion, bool bForceState, bool bNoStateReligion);

CyGameTextMgr.cpp

Code:
std::wstring CyGameTextMgr::getReligionHelpCity(int iReligion, CyCity* pCity, bool bCityScreen, bool bForceReligion, bool bForceState, bool bNoStateReligion)
{
	CvWStringBuffer szBuffer;
	GAMETEXT.setReligionHelpCity(szBuffer, (ReligionTypes)iReligion, ((pCity != NULL) ? pCity->getCity() : NULL), bCityScreen, bForceReligion, bForceState, bNoStateReligion);
	return szBuffer.getCString();
}
 
No python function call exists without adding your new field to a Cy___Interface.cpp file. So you need to add a line to CyGameTextMgrInterface.cpp which tells the interface what CyGameTextMgr.cpp function to call when given an order from python.
 
Thanks!!!!!!! :D :o

Bah, I dislike opening SDK functions or widgets to python. You seem to spend more time writing service code than your core code itself. :(
 
Does anyone know how to give a "no city" input in the CyGameTextMgr().getReligionHelpScreen(iLinkReligion, pLoopCity.GetCy()) function? I tried 'NULL' and '-1', but both gave a python error.
 
Can you give some context? I would expect NULL to work.

Edit: Wait, is this Python code you're writing? If so, use None. None is essentially Python's NULL.
 
What about creating an empty CyCity object? This way it's a valid Python object that will respond appropriately to the isNone() function call, but point to a NULL CvCity (I expect but haven't tested).

Code:
CyGameTextMgr().getReligionHelpScreen(iLinkReligion, [B]CyCity()[/B])

Edit: First of all, there is no getReligionHelpScreen(). There is getReligionHelpCity() which also takes four boolean parameters after the CyCity. I assume this is what you wanted.

I tried a test game calling with both CyCity() and None, and both return an empty string. When I pass in my capital city which only has Buddhism, I get

Judaism
+1​

WTH? :confused: What exactly are you hoping to have happen?

Note: I'm working on the BAT 1.2 installer, so I haven't taken the time to open the cpp file right now and see what it's supposed to return.
 
Can you give some context?

The context was in the previous posts. I added a new function myself.

I've tried to do the same with NearestCity functions. IIRC None didn't work either. To get a null pointer, I cheated by asking the Barbarian Civilization for a pointer to their capital city.

Cool idea! :lol:

I tried a test game calling with both CyCity() and None, and both return an empty string.

Thanks! :)

WTH? :confused: What exactly are you hoping to have happen?

See attachment. :D
 
Top Bottom