NQualityOfLife.XML.Iterate - Niilo007/RimWorld-NQoL GitHub Wiki

Iterate

Related:


XML

<Operation Class="NQualityOfLife.XML.Iterate">
    <xpath>string</xpath>
    <toVar>string</toVar> <!-- Optional -->
    <count>string</count> <!-- Optional -->
    <applyVariables>bool</applyVariables> <!-- true -->
    <item Class="PatchOperation">

    </item>
    <done Class="PatchOperation"> <!-- Optional -->

    </done>
    <error Class="PatchOperation"> <!-- Optional -->

    </error>
</Operation>

Usage

The Iterator substitutes {i} with xpath[i] where i is the index of the item.
So:

<Operation Class="NQualityOfLife.XML.Iterate">
    <xpath>Defs/HeadTypeDef</xpath>
    <item Class="NQualityOfLife.XML.Log">
        <xpath>{i}/defName</xpath>
        <error Class="NQualityOfLife.XML.Log">
            <xpath>{i}</xpath>
        </error>
    </item>
</Operation>

Would look like this:

<Operation Class="NQualityOfLife.XML.Iterate">
    <xpath>Defs/HeadTypeDef</xpath>
    <item Class="NQualityOfLife.XML.Log">
        <xpath>Defs/HeadTypeDef[i]/defName</xpath>
        <error Class="NQualityOfLife.XML.Log">
            <xpath>Defs/HeadTypeDef[i]</xpath>
        </error>
    </item>
</Operation>

<xpath>

Used to select the nodes to iterate.
Supports variables.


<applyVariables>

Apply variables to the xpath and to the text contained in value?


<toVar>

The xpath gets stored in this variable if provided.

  • If <toVar> is provided, the given <xpath> is saved to it.
    • Variable names must begin and end with '{' & '}'

<count>

The count of iterated items gets stored in this variable if provided.


<item>

The patch operation that gets applied to each matching item.


<done>

The patch operation to perform when this one has completed successfully.


<error>

The patch operation to perform if this one fails or errors.


Errors


Examples

Used In Example:

<Operation Class="NQualityOfLife.XML.Iterate">
    <xpath>Defs/HeadTypeDef</xpath>
    <item Class="PatchOperationSequence">
        <operations>
            <li Class="NQualityOfLife.XML.AddTextVariable">
                <toVar>{myVar}</toVar>
                <xpath>{i}/defName</xpath>
                <error Class="NQualityOfLife.XML.AddTextVariable">
                    <toVar>{myVar}</toVar>
                    <value>null</value>
                </error>
            </li>
            <li Class="NQualityOfLife.XML.Log">
                <message>{i} -> {myVar}</message>
                <done Class="NQualityOfLife.XML.ClearVariable">
                    <name>{myVar}</name>
                </done>
            </li>
        </operations>
    </item>
</Operation>

⚠️ **GitHub.com Fallback** ⚠️