Editing Modding Tutorials/XML file structure
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 64: | Line 64: | ||
</Def> | </Def> | ||
</Defs></source><br/> | </Defs></source><br/> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Inheritance= | =Inheritance= | ||
− | ''Summary'': In XML, inheritance is used to decrease redundancy. If something has a ParentName="YourParentName", it takes all contents from Name="YourParentName". In case this ParentName is incomplete this will crash the game, and you stop it from being loaded into the game with Abstract="True".<br/><br/> | + | '''Summary''': In XML, inheritance is used to decrease redundancy. If something has a ParentName="YourParentName", it takes all contents from Name="YourParentName". In case this ParentName is incomplete this will crash the game, and you stop it from being loaded into the game with Abstract="True".<br/><br/> |
− | + | Note that after update A15, abstracts have been directly inheritable from the core and from other mods. Redefining the core abstracts is common cause for mod compatibility issues, because any mod loaded after the abstract has been redefined will use the modified version instead of the core. Therefore, when defining abstracts for a mod, it's advisable to try to avoid overwriting the core abstracts and to instead use unique names that are unlikely to be accidentally used by other mods. | |
===Basegun ThingDef=== | ===Basegun ThingDef=== | ||
− | The first thing in '' | + | The first thing in ''Weapons_Guns.xml'' is a '''<ThingDef>''' with a Name and Abstract ''type'':<br/> |
− | <source lang="xml"><ThingDef | + | <source lang="xml"><ThingDef Name="BaseGun" Abstract="True"></source><br/> |
− | The Abstract type means that contents of this '''<ThingDef>''' will not be loaded into the game, that after reading and processing the information in this tag it (the game) will finish reading the XML | + | The Abstract type means that contents of this '''<ThingDef>''' will not be loaded into the game, that after reading and processing the information in this tag it (the game) will finish reading the XML file ('''entire mod folder as of Alpha 13''') and '''discard''' this tag and its contents, leaving alone (not discarding) anything that might have copied (taken, inherited) the contents of it. All of this is done with this tag:<br/> |
<source lang="xml"><ThingDef Abstract="True"></source><br/> | <source lang="xml"><ThingDef Abstract="True"></source><br/> | ||
− | So what that means is that all the ''contents'' of <code lang="xml"><ThingDef | + | So what that means is that all the ''contents'' of <code lang="xml"><ThingDef Name="BaseGun" Abstract="True"></code> can be used over and over in the various guns, but '''BaseGun''' itself does not exist in the game - it's an abstract idea!<br/> |
The Name type means the contents of this '''<ThingDef>''' can be ''inherited'' by (read: copied by) another '''<ThingDef>'''. This way you can write everything you're going to repeat a lot throughout the file in a single location, such as the following:<br/> | The Name type means the contents of this '''<ThingDef>''' can be ''inherited'' by (read: copied by) another '''<ThingDef>'''. This way you can write everything you're going to repeat a lot throughout the file in a single location, such as the following:<br/> | ||
Line 93: | Line 85: | ||
Which notifies that this '''<ThingDef>''' is of the ''Item'' category, as opposed to those of the ''Building'' category. Because there's a lot of ''tags'' repeated throughout every thing, this greatly compacts the XML file.<br/> | Which notifies that this '''<ThingDef>''' is of the ''Item'' category, as opposed to those of the ''Building'' category. Because there's a lot of ''tags'' repeated throughout every thing, this greatly compacts the XML file.<br/> | ||
− | The full | + | The full BaseGun parent only has to be defined once in a file, and can then be inherited (copied) with:<br/> |
− | <source lang="xml"><ThingDef ParentName=" | + | <source lang="xml"><ThingDef ParentName="BaseGun"></source><br/><br/> |
'''<ThingDef ParentName="Parent">''' inherits all contents from '''<ThingDef Name="Parent">'''. <br/> | '''<ThingDef ParentName="Parent">''' inherits all contents from '''<ThingDef Name="Parent">'''. <br/> | ||
Line 100: | Line 92: | ||
<source lang="xml"><useHitPoints>False</useHitPoints></source><br/> | <source lang="xml"><useHitPoints>False</useHitPoints></source><br/> | ||
− | The | + | The last '''<ThingDef>''' on top of the file is one with the Name type ''BaseHumanGun'' and the ParentName type ''BaseGun''. It inherits the contents of BaseGun and is inherited by everything with '''<ThingDef ParentName="BaseHumanGun">''':<br/> |
− | <source lang="xml"><ThingDef Name="BaseGun" Abstract="True | + | <source lang="xml"><ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True"></source><br/><br/> |
− | |||
− | |||
A list representation of how inheritance works in Rimworld's XML might help you out, either early on or to collect your thoughts after reading the above.<br/><br/> | A list representation of how inheritance works in Rimworld's XML might help you out, either early on or to collect your thoughts after reading the above.<br/><br/> | ||
Line 117: | Line 107: | ||
##* All interfering content from parents is now overwritten | ##* All interfering content from parents is now overwritten | ||
## Now that all <Def>s know their contents, ABSTRACT type defs are discarded and therefore ignored by the game | ## Now that all <Def>s know their contents, ABSTRACT type defs are discarded and therefore ignored by the game | ||
− | ## All <Def>s and their contents finish loading | + | ## All <Def>s and their contents finish loading |
# Game finishes loading mods<br/><br/> | # Game finishes loading mods<br/><br/> | ||
===Breakdown=== | ===Breakdown=== | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Let's break down the inheritance chunks of the BaseGun code:<br/> | |
− | + | <source lang="xml"><ThingDef Name="BaseGun" Abstract="True"> | |
− | </ | ||
− | |||
− | |||
</ThingDef> | </ThingDef> | ||
<ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True"> | <ThingDef Name="BaseHumanGun" ParentName="BaseGun" Abstract="True"> | ||
− | |||
− | |||
</ThingDef> | </ThingDef> | ||
− | |||
− | |||
+ | <ThingDef Name="BaseBullet" Abstract="True"> | ||
+ | </ThingDef></source> | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 175: | Line 153: | ||
* '''<Defs>''' is the rootnode and this uniformity is enforced. | * '''<Defs>''' is the rootnode and this uniformity is enforced. | ||
* '''<Def>''' has to have a specific name, matching a Type in C#. | * '''<Def>''' has to have a specific name, matching a Type in C#. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Next up= | =Next up= |