SDK debug messages

alpaca

King of Ungulates
Joined
Aug 3, 2006
Messages
2,322
A simple question: how can I display simple messages from SDK code (for example for checking if a certain feature worked)? Something like std::cout but with screen output if possible. Logging would work, too, but is more fuss of course.

Thanks in advance for any help
 
To log to the screen one method is to use gDLL->getInterfaceIFace()->addMessage(); this creates an event message like you normally see at the start of a turn.

Prototype:
Code:
addMessage(PlayerTypes ePlayer, bool bForce, int iLength, CvWString szString, LPCTSTR pszSound = NULL,
		InterfaceMessageTypes eType = MESSAGE_TYPE_INFO, LPCSTR pszIcon = NULL, ColorTypes eFlashColor = NO_COLOR,
		int iFlashX = -1, int iFlashY = -1, bool bShowOffScreenArrows = false, bool bShowOnScreenArrows = false)

Example (from CvPlayer::doEspionageMission()):
Code:
gDLL->getInterfaceIFace()->addMessage(getID(), true, GC.getEVENT_MESSAGE_TIME(), gDLL->getText("TXT_KEY_ESPIONAGE_MISSION_PERFORMED"), "AS2D_POSITIVE_DINK", MESSAGE_TYPE_INFO, ARTFILEMGR.getInterfaceArtInfo("ESPIONAGE_BUTTON")->getPath(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), iX, iY, true, true);


To log to a file, use gDLL->logMsg().

Prototype:
Code:
logMsg(const TCHAR* pLogFileName, const TCHAR* pBuf, bool bWriteToConsole=false, bool bTimeStamp=true)

Example (From CvGlobals::getInfoTypeForString):
Code:
		CvString szError;
		szError.Format("info type %s not found, Current XML file is: %s", szType, GC.getCurrentXMLFile().GetCString());
		FAssertMsg(strcmp(szType, "NONE")==0 || strcmp(szType, "")==0, szError.c_str());
		gDLL->logMsg("xml.log", szError);
 
Thanks. I already stumbled upon the addMessage thing, the problem is that I need a player for that, right? Is it possible to somehow get the human player from the global context and send him the message?

I also found out that I can use a false FAssert (in a debug build at least) which has the added advantage (or disadvantage) that it stops game execution.
 
This should work to get the ID of the active player, which is the human in a single-player game.
Code:
GC.getGameINLINE().getActivePlayer()

Interesting idea with using FAssert in that way.
 
This should work to get the ID of the active player, which is the human in a single-player game.
Code:
GC.getGameINLINE().getActivePlayer()

Interesting idea with using FAssert in that way.

Thanks :)
The FAssert thing appears to be especially useful when you try to test something during the loading stage with the debugger because it's kind of like a break point which gives you a lot of time to attach your debugger to the process.
 
Top Bottom