Question pulling xml text into sdk messages..

Kailric

Jack of All Trades
Joined
Mar 25, 2008
Messages
3,100
Location
Marooned, Y'isrumgone
I am wanting to make it so if you rename your ship with a persons name, like "Captain Jack Sparrow" when you get messages about that unit it doesn't say "Your Captain Jack Sparrow blah blah blah". Instead of rewriting all the text files I am trying to pull one tag from xml text file and place it in another xml file and then display the information to the player via the "gDLL-getInterfaceIFace()->addMessage" in the SDK.

These lines:

<Tag>TXT_KEY_YOUR</Tag>
<English>Your</English>

<Tag>TXT_KEY_CAPTAIN</Tag>
<English>Captain</English>

are in my text files.


This is my code but the message appears corrupted and neither Your or Captain will appear, nor the name of the unit. What do I need to do to fix it.

Example?
Code:
CvWString szYourorCaptian;
    if (!hasCaptain())
    {
        szYourorCaptian = gDLL->getText("TXT_KEY_YOUR");
    }
    else
    {
        szYourorCaptian = gDLL->getText("TXT_KEY_CAPTIAN");
    }
    CvWString szBuffer = gDLL->getText("TXT_KEY_UNIT_ACTION", szYourorCaptian, getNameOrProfessionKey());
    gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), false, GC.getEVENT_MESSAGE_TIME(), szBuffer, "AS2D_BUILD_BANK", MESSAGE_TYPE_INFO, NULL, (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"));
Code:
<TEXT>
    <Tag>TXT_KEY_UNIT_ACTION</Tag>
    <English>%s1 %s2_UnitName has died</English>
 
To begin with then there is a discrepancy in the way you spell Captain(switching the 'a' and 'i'), but I don't see why that should cause no text being displayed at all.

I can't really come with any further suggestions without having seen the code for the function getNameOrProfessionKey(), but I suspect that might be the actual culprit.
 
To begin with then there is a discrepancy in the way you spell Captain(switching the 'a' and 'i'), but I don't see why that should cause no text being displayed at all.

I can't really come with any further suggestions without having seen the code for the function getNameOrProfessionKey(), but I suspect that might be the actual culprit.


Thanks for the suggestions. I understand more about C++ than I do XML atm and I am just learning both and self taught at that. Yeah, the Captain miss spell was just a typo on here. Anyway, I got it to work somewhat the way I wanted by useing the "szString.append" command I found used often in the code. My code that works is this:

Code:
const CvWString CvUnit::getTextyc(CvWString szStringText) const
{
    CvWString szString;

    if (!hasCaptain())
    {
        szString.append(gDLL->getText("TXT_KEY_YOUR"));
    }
    else
    {
        szString.append(gDLL->getText("TXT_KEY_CAPTAIN"));
    }
    szString.append(L" ");
    szString.append(szStringText);

	return szString;
}

I use the "szString.append(L" ");" just to add a space between the "Your Privateer" not sure if thats the best way to do that or not.

Anyway, the code for the "getNameOrProfessionKey()" function is:

Code:
const wchar* CvUnit::getNameOrProfessionKey() const
{
	if(getProfession() != NO_PROFESSION)
	{
		return GC.getProfessionInfo(getProfession()).getTextKeyWide();
	}
	else
	{
		return getNameKey();
	}
}

You know I just figured out what is going on here. There is also a funtion called "const wchar* CvUnit::getNameOrProfession const" I haven't really noticed that yet. I would assume one returns the "key" such as "TXT_KEY_CAPTAIN" and the other returns what the key points too that is "Captain".

Thats what I figured out so far anyway.
 
ah if you can handle C++ then XML will be a breeze very shortly. Its like comparing trigonometry against addition and subtraction. You can literally be an XML Expert in a matter of weeks or months, its cake compared to any programming language.

I'm sure you'll be slicing right through it all w/o problems in no time.
 
Back
Top Bottom