• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days (this includes any time you see the message "account suspended"). For more updates please see here.

XML Tips, Tricks & Examples

Tekinette

Chieftain
Joined
Sep 15, 2009
Messages
35
Ok so I'm a novice at this but from what I've tried so far when updating a xml you can do it like this :

Code:
<GameData>
	<Colors>
		<Update>
			<Set Red="1" Green="0.55" Blue="0.55"></Set>
			<Where Type="COLOR_PLAYER_AZTEC_ICON"></Where>
		</Update>
		<Update>
			<Set Red="0.08" Green="0.45" Blue="0.2"></Set>
			<Where Type="COLOR_PLAYER_AZTEC_BACKGROUND"></Where>
		</Update>
	</Colors>
</GameData>

So you can write several <set> commands if it's using the same <where>, and the other way around works aswell of course (several <where> commands). This wasn't very clear in Kael's Guide, I believe he only mentionned the several <where> but his examples always used a new line for each <set> so I'm posting this just in case some of you didn't already know this.

By the way this example changes the Aztec civ colors, the values are in Arithmetic RGB ( 1,1,1 = white ; 0,0,0 = black ; 1,0,0 = full red )

This is very simple but I'm sure others can post in this thread more usefull tips & examples :)
 
This is a good tip, but I recommend you use this forum's code tags to wrap your code in so we get all the indentation and stuff. ;)

Otherwise, good stuff. :thumbsup:
 
Some things I discovered after some pretty annoying head-to-desk troubleshooting.

1. If you have some XML error in your files (not certain if this is for all types of errors), the mod (re)building will not warn you but the mod will fail silently for all XML changes, sometimes even on other files. The only way to see that it's not working, is to check the debug database (and see that the values remain the same) or to make some change in the game setup (eg, change some help text) which will notify you that your changes are not being applied.

For example, in my mod, I had some updates on the defines table via XML, however I had forgotten to wrap 2 updates with the <update> tag. It looked like this

Code:
		<Update>
			<Where Name="HAPPINESS_PER_EXTRA_LUXURY"/>
			<Set Value="1"/>
		</Update>
		<Update>		
			<Where Name="UNHAPPINESS_PER_CITY"/>
			<Set Value="1"/>
		</Update>
			<Where Name="UNHAPPINESS_PER_POPULATION"/>
			<Set Value="0.5"/>
		<Update>
			<Where Name="MIN_CITY_RANGE"/>
			<Set Value="6"/>
		</Update>

And when you have a whole page of them, it's not easy to see. It turned out, that the game was failing to load the whole XML file while I thought that only one variable wasn't being changed.

A thing that alerted me often of an XML failure is that I had modified the help popup for the map sizes to display "(Large Scale Mod version)" in the end. When the XML failed on the global variables or in other places, very often the extra text would not appear, and I would then know that the mod is not working correctly. Checking the DB confirmed it of course.

2. Game has an issue with decimals. I was trying to change the help description of the map sizes, as mentioned above, and when I used "1.5" within the help string, the XML always failed (silently of course). No idea why. When I removed the "1.5" part, it worked normally. I also noticed it when changing a numerical value to 0.5, although changing it to 0.50 then worked and changing it back to 0.5 continued working. No idea what the hell is going on here :)

Hopefully these help people avoid the frustration I had today :)
 
When you build a new version of your mod, if the mod was active in the game before you built it, it will remain active but hidden for you, likely causing issues with sql statements that increment values. Discovered this here

This does affects mods loaded from the mod server.
 
On the topic of sets and wheres, you can do either of these:

Code:
<Set a="b"  />
<Where x="y" />

<Where a="b" />
<Set x="y" />

Space or none before the /> doesn't matter either, I include the space to make long lists of these easier to read. You sometimes see set before where simply because in sql, the most common task is to find something:

Code:
SELECT somethingtofind
WHERE condition

In this situation it makes sense to put what you're looking for first. When actually setting values in a table however, it can make more sense to say "where building is granary" "set cost to 50". This is the order in the default game files, because each row in a table typically has a row header, followed by a list of data. It doesn't matter either way however, and is simply up to the individual.


You can include multiple conditions in each:
Code:
<Where w="x" y="z" />
<Set a="b" c="d" e="f" />

Multiple conditions in a "where" are AND'd together (all conditions must be true).


You can also break apart the statements:

Code:
<Where>
      w="x"
      y="z" 
</Where>
<Set>
      a="b"
      c="d"
      e="f"
</Set>

This can be helpful if you have a lot to change for a particular entry.
 
If you plan on modifying the terrain values, you should know that forests don't take into account the terrain it's on, a forest on tundra will give the same output as a forest on grasslands or plains. It should be possible to find a way arround this but I haven't tried yet.

Also, the best way to test a mod quickly is to create a scenario on a small map (quicker to load) with all the things you need (terrains, units, tech, lots of money, lots of policy points etc..) and keep Civ open in windowed mod and reload the scenario each time you update the mod. To start Civ in window mod, simply change "FullScreen = 1" to "FullScreen = 0" in GraphicsSettingsDX9.ini and/or GraphicsSettingsDX11.ini in the Users/My Documents/My Games/Sid Meiers's Civilization 5/ folder.
 
Excellent point about a small scenario map! It can also help to load it in the Singleplayer menu first, as map selections in the Mods menu don't get stored between one game and the next.

Along those lines, there's also a "Fullscreen" option in the game's Video Options. If you uncheck this the game is in windowed mode, and if you quit the game it'll restart in this mode.
 
If you modify a leader trait, then you will not see the changes until you start a new game. Loading a previous game will use the leader trait as it was when the game was setup.
 
Just wanted to add some tips on using SQL as it seems to fit in here. I find it more readable than xml changes. And the good thing is that you can test it with the FF addon to see if the statement actually changes a value without the need of the game.

Some examples:

Code:
UPDATE Technologies SET Era="ERA_MEDIEVAL",GridX="5",GridY="0",Cost="1300" WHERE Type="TECH_ASTRONOMY";
UPDATE Technologies SET GridX="4" WHERE Type="TECH_COMPASS";
UPDATE Technology_PrereqTechs SET PrereqTech="TECH_COMPASS" WHERE TechType="TECH_ASTRONOMY";
UPDATE Technologies SET GridX=GridX+1 WHERE GridX>5;

These statements for example make the changes and they take less lines than the xml equivalent. Just need to be careful with massive changes like last one, and using quotes in some parts (basically numbers vs text).

I am now investigating how to add elements with SQL, if anyone has any info it will be appreciated.
 
I am now investigating how to add elements with SQL, if anyone has any info it will be appreciated.

An insert statement would normally look like this:

Code:
INSERT INTO Technologies(Type,GridX,GridY) VALUES("TECH_MYTECH",1,2);

You can also use INSERT with SELECT:
Code:
INSERT INTO Technologies(Type,GridX,GridY) SELECT Type+"_FOO",GridX,GridY+10 FROM Technologies;

Haven't tested either of the above with the game or SQLite but that's the standard syntax in most common forms of SQL. HTH
 
Back
Top Bottom