XML Structure Help

johnnyward88

Chieftain
Joined
Nov 3, 2014
Messages
2
Location
UK
Hi,

I have successfully create a mod to update the Explorer Combat (I didn't see the one in workshop until afterwards!)

My question is this, how do I structure the XML so that I can update more than one unit OR more than one element of a unit:

e.g.

I want to set Marine combat and Explorer combat to larger amounts so I have:
Code:
<GameData>
	<Units>
		<Update>
			<Set Combat="10"/>
			<Where Type="UNIT_EXPLORER"/>
		</Update>
	</Units>
</GameData>

and I want to add in the soldier, so do I add it within the Units tag:

Code:
<GameData>
	<Units>
		<Update>
			<Set Combat="10"/>
			<Where Type="UNIT_EXPLORER"/>
		</Update>
		<Update>
			<Set Combat="20"/>
			<Where Type="UNIT_MARINE"/>
		</Update>
	</Units>
</GameData>
OR a new Units Tag:
Code:
<GameData>
	<Units>
		<Update>
			<Set Combat="10"/>
			<Where Type="UNIT_EXPLORER"/>
		</Update>
	</Units>
	
	<Units>
		<Update>
			<Set Combat="20"/>
			<Where Type="UNIT_MARINE"/>
		</Update>
	</Units>
</GameData>
Or is there another way as I can't get either to work!

Likewise where would I put the <Set><Where> for a second element of the same unit e.g. changing cost and combat of a single unit?

Thanks in advance for the assistance :)
 
See this XML/SQL cheat sheet.

Either one of your proposals should work (i.e., with the second, you're just finishing your changes to the Units table, and then starting a new set of changes; same result). If it didn't work, there's either some other error earlier in the file (check your database.log) or maybe you've forgotten to set the file OnModActivated > UpdateDatabase.

You can add additional elements to change in one update thusly:
Code:
	<Units>
		<Update>
			<Set Combat="10" Cost="30"/>
			<Where Type="UNIT_EXPLORER"/>
		</Update>
	</Units>

You can refine your <Where>'s similarly by adding another condition to ensure that changes will be made to the row only where two values both exist in that row.

You can do some interesting things with SQL that you can't with XML (both are just techniques to modify the SQLite database). For instance, this would double the costs of the Explorer and the Soldier:
Code:
UPDATE Units SET Cost = Cost * 2 WHERE Type = 'UNIT_EXPLORER' OR Type = 'UNIT_MARINE';
 
Wow, all very useful! Thank you so much for taking the time to respond.

Hopefully now I understand the structures better I can roll out my Mods more effectively!

I did see another post relating to checking the database.log and sure enough I did have a typo in one XML. I will tidy up the code and re-test now :)
 
Top Bottom