adding XML tags with SDK

juni_be_good

Black mage
Joined
Jun 26, 2005
Messages
115
Location
Caen, France
Hello

I am trying to allow techs to bring a free unit to all civs (and not only the first who discovers it). For that I added a FreeUnitClass tag after the existing FirstFreeUnitClass, with a minOccurs set to 0 (for easier use). When I launch my mod with just these XML changes, it loads perfectly.

I am now working on SDK to make the game able to read it. Everything is correct except one line that is not working.

In the CvTechInfo::read(CvXMLLoadUtility* pXML), I saw this code was used for FirstFreeUnitClass tag :

Code:
pXML->GetChildXmlValByName(szTextVal, "FirstFreeUnitClass");
	m_iFirstFreeUnitClass = pXML->FindInInfoClass(szTextVal, GC.getUnitClassInfo(), sizeof(GC.getUnitClassInfo((UnitClassTypes)0)), GC.getNumUnitClassInfos());

So I added this line for my custom tag :

Code:
pXML->GetChildXmlValByName(szTextVal, "FreeUnitClass");
	m_iFreeUnitClass = pXML->FindInInfoClass(szTextVal, GC.getUnitClassInfo(), sizeof(GC.getUnitClassInfo((UnitClassTypes)0)), GC.getNumUnitClassInfos());

DLL compiles properly, but when I launch my mod, I get an error message about a Tag (without name) that it is unable to find.

I'm sure my mistake is on this line, because if I remove it, my mod loads well. Does anyone know where I'm wrong ?
 
Have you actually added the tag to the relevent TechInfos.xml file and-more importantly-to the TechInfosSchema.xml? If not, then that may well be your problem.

Also, note that just because you have added this new tag to CvInfos, doesn't mean it will do anything in-game (that was my mistaken belief in the early days :mischief: ).
What you will need to do is go into CvTeam and search for ::processTechs. Have a look in there and you will probably find the section you need for granting the free unit. You might need to take the existing code for free units from bIsFirst, and apply it at a different step of the tech process. Hope this helps.

Aussie_Lurker.
 
Yes, I have already added the Tag to XML files (including the schema), and I know that my tag will do nothing for now, but I can not work further if my mod don't load with this new tag. :)

As I told, my mistake is surely in the line I mentioned. With this line, my mod crashes, without this line, it loads.
 
Then I am at a loss to explain why it isn't working. Just tell me, though, it is crashing at the part where it is loading the XML files, would this be correct? If so, and its saying something like 'Expecting <this tag>, then you have some kind of parsing error. Go over your CvTechInfo file and make sure that your new tag appears EXACTLY where it does in the Schema file. Seriously, I cannot think of any other suggestions, but best of luck with the mod :).

Aussie_Lurker.
 
Things happen just like you said : game crashes while loading XML files. But I don't get the name of the unexpected tag in the error message. My message is "Tag : is incorrect in Civ4TechInfos.xml".
My tag is placed correctly, and I get the error message even if I don't use the tag (I set its minOccurs to 0 in the schema, so I don't have to put it for every tech)

I tried to load my mod with standard DLL, so just with XML changes, and then it loads. It means that the way I define and use my tag in XML is right. It's the way I try to read it in SDK that is wrong.
 
I'm finding the same prb for another use (add a tag to improvments) so I couldn't help you.

When I load the XML I find the same crush error... Failed loading 1stly TerrainInfo.xml and after clicking "ok" I recive a second error popup saying failed loading techinfos.xml.

I guess It's not a real prb of code inside those xml files becuase consider that both TerrainInfo and TechInfo where the original ones for me.

For sure is a prb of getXML into C++.
Sorry for not beeing able to solve your prb but I'm still studying base and try to understain my error... :(
 
I found a way to fix it, and I have no idea on why it works but... it works. :)
I removed the minOccurs=0 in my schema and made a copy/paste party to put the tag on every tech. :D I didn't change anything else, and now my mod loads perfectly. :wow:

I don't know why I had the mistake only when I tried to change SDK files and not before, when I just ave changed XML. It is weird. Anyway, thanks for helping me Aussie_Lurker, and I hope this will help Duke to solve his problem too ;)
 
This error is normal for new tags not appearing in all units/buildings/techs etc.

You have to pass a default value to the function, which reads the tag.
It should look like this:
Code:
pXML->GetChildXmlValByName(szTextVal, "FreeUnitClass", "NONE");

Matze
 
it keeps on returning me that error even if I inserted this code:
Code:
pXML->GetChildXmlValByName(szTextVal, "iOilExtractionPerTurn");
	m_iOilExtractionPerTurn = pXML->FindInInfoClass(szTextVal, GC.getImprovementInfo(), sizeof(GC.getImprovementInfo((ImprovementTypes)0)), GC.getNumImprovementInfos());

plus adding tag to each improvement.

But I was asking me... TerrainInfos.xml doesn't have nothing to deal with improvement tags or I missed something?
 
Improvements tags are in Civ4ImprovementInfos.xml. Sounds logical to me :D

You should try what Matze said, add a default value to your reading instruction, it might work.
 
What do you mean exactly with assinigning a defoult value to the XMLget function?
I didn't understand...

About XML loading error, I'm nearly sure it's a prob inside the ImprovementInfo file it already happened to me to have a crush error on a file that wasn't directly related to my modded files but recalled somehow.
 
It means that instead of a code line that looks like this :
Code:
pXML->GetChildXmlValByName(szTextVal, "FreeUnitClass");

you should put this kind of code :
Code:
pXML->GetChildXmlValByName(szTextVal, "FreeUnitClass", "NONE");

The third argument means that in case of a missing (or empty) tag, the program must replace the value by "NONE"
 
Nothing it keeps on returning me this (I made 3 shoots of error it returns)
 

Attachments

  • Bug XML1.jpg
    Bug XML1.jpg
    57.2 KB · Views: 111
  • Bug XML2.jpg
    Bug XML2.jpg
    57.9 KB · Views: 88
  • Bug XML3.jpg
    Bug XML3.jpg
    28 KB · Views: 89
so noone knows which could be the reason?

PLS PLS PLS I cannot go on with testing and programming... I really don't have the most little idea about the reason why this shouldn't be working...
:hammer2: :wallbash: :wallbash: :badcomp: :religion: :religion: :religion:
 
Look, I can't see any reason why it isn't working just from what you have here. Could you upload all the effected files, so that I can have a look at them? Oh and please tell me you have written in the code where all your changes have been made-or else finding them will be a nightmare ;).

Aussie_Lurker.
 
Top Bottom