Using the standard library.

The code looks like <srai>XCAR AB, CD</srai>

But the stack trace shows [0] srai of XCAR AB,CD with the space removed.

Using Pandorabots.com.

I'm trying to loop though a string of , -delineated words of uniform length using XSUBSTRING, in order to map each one to a human-readable output.

So I'm using a nested category to get and print the XCAR of each XSUBSTRING based on the updated index predicate from the outer category.

Here's the code for the outer category:

<category>
    <pattern>COMMAND</pattern>
    <template>
        <think>
            <set name="index">0</set>
            <set name="allitemsprinted">FALSE</set>
        </think>
        
        This part prints for me.
        <br/><br/>
        So does this.
        
        <!-- iterate through "ties" -->
        <condition name="allitemsprinted" value="FALSE">
            But this doesn't print.
            Nor does anything after.
            This srai works correctly:
            <srai>XCDR UX, SE, CS</srai>
            <srai>PRINT ITEM</srai>
            <loop/>
        </condition>
        
        <br/>
    </template>
</category>

And here's the nested category:

<category>
    <pattern>PRINT ITEM</pattern>
    <template>
        <think>
            <set var="itemlocation">
                <!-- 2-char name plus delim -->
                <srai>XMUL <get name="index"/> XS 4</srai>
            </set>
            
            <set var="remainingitems">
                <srai>XSUBSTRING <get name="items"/> XS <get var="itemlocation"/></srai>
            </set>
            
            <!-- increment index -->
            <set name="index">
                <map name="successor">
                    <get name="index"/>
                </map>
            </set>
            
            <!-- check for end of list -->
            <set name="allitemsprinted">
                <srai>XGT <get name="index"/> XS <get name="itemcount"/></srai>
            </set>
        </think>
        
        Remaining items: <get var="remainingitems"/>
        
        First remaining item: <srai>XCAR <get var="remainingitems"/></srai>
        
        <!-- human-readable output -->
        <map name="itemsreadable">
            <srai>XCAR <get var="remainingitems"/></srai>
        </map>
        <br/>
    </template>
</category>

The stack trace provided by Pandorabots shows that the <srai> inside the <condition> does indeed get called. But it won't print anything at all.

1

There are 1 best solutions below

1
On BEST ANSWER

First, make sure normal.substitution has an entry for removing commas [",", ""], as it's very rare that the bot needs to process commas.

Assuming your map is something like this:

[
    ["UX", "User Experience"], 
    ["SE", "Sales Entry"], 
    ["CS", "Customer Services"]
]

You can then do this to get human readable output (you don't need the standard library for this):

<category>
    <pattern>COMMAND</pattern>
    <template>
        <think><set name="itemlist">UX, SE, CS</set></think>
        <srai>PRINT ITEM <get name="itemlist"/></srai>
    </template>
</category>

<category>
    <pattern>PRINT ITEM * *</pattern>
    <template>
        <map name="itemsreadable"><star/></map><br/>
        <srai>PRINT ITEM <star index="2"/></srai>
    </template>
</category>

<category>
    <pattern>PRINT ITEM *</pattern>
    <template>
        <map name="itemsreadable"><star/></map>
    </template>
</category>

This will produce the following:

enter image description here