Hello all! This one is most likely a silly syntax issue, but I might also be confusing TW with the structure I’m using. In any case, I’m completely puzzled and would love any help.
I have dictionary tiddlers (simple key:value
pairs inside), listing spell names and their corresponding levels:
spell1 name:level
spell2 name:level
...
spell3 name:level
(I call those tiddlers “spellbooks”)
In another regular tiddler holding information on a character, a spellbook
field indicates what dictionary tiddler holds the list of spells that character knows, and how high level he/she does.
Inside the character tiddler, I’m listing the contents of the field-specified spellbook of this character like so:
<$let spellbook={{!!spellbook}}>
''Spellbook'': <$link to=<<spellbook>>/>
<$macrocall $name="gurpsspelltable" spells="[<spellbook>indexes[]]"/>
</$let>
… where the gurpsspelltable
macro is defined as:
\define gurpsspelltable(spells)
<table class="max">
<tr>
<th align="left">Spell</th>
<th align="center">Level</th>
<th align="center">College</th>
<th align="center">Class</th>
<th align="center">Base cost</th>
<th align="center">Additional cost</th>
<th align="center">Time to cast</th>
<th align="center">Duration</th>
<th align="center">Prerequisites</th>
</tr>
<$list filter="$spells$" template=GURPSSpellTableRowTemplate variable="spell"/>
</table>
\end
… then the template GURPSSpellTableRowTemplate
generates the row for each of the keys in the spellbook dictionary tiddler, i.e spell1 name, spell2, ..., spelln
:
<$let level={{{ [<spellbook>getindex<spell>] ~0 }}}> <!-- displays "0" if the <<spell>> index does not exist or is blank -->
<tr><td><$link to=<<spell>>/></td>
<td><<level>></td>
<td>{{{ [<spell>get[college]] }}}</td>
<td><$let class={{{ [<spell>get[class]] }}}><<class>></$let></td>
<td><$let basecost={{{ [<spell>get[base_cost]] }}}><$macrocall $name="cost-fp" value="<<basecost>>"/></$let></td>
<td><$let addcost={{{ [<spell>get[additional_cost]] }}}><$list filter="[<addcost>split[ ]]" variable="seg"><% if [<seg>regexp[\d+]] %><$macrocall $name=cost-fp value=<<seg>> /> <% else %><<seg>> <% endif %></$list></$let></td>
<td><$let ttc={{{ [<spell>get[casting_time]] }}}><$macrocall $name="time" value="<<ttc>>"/></$let></td>
<td><$let dur={{{ [<spell>get[duration]] }}}><$macrocall $name="duration" value="<<dur>>"/></$let></td>
<td><$let prereq={{{ [<spell>get[prerequisites]] }}}><$list filter="[<prereq>split[, ]]" variable="segm" join=", "><$link to=<<segm>>/><% if [[[<spellbook>indexes[]]!contains[<segm>]] %>
(!)<% endif %></$list></$let></td></tr>
</$let>
The issue resides in the last row, which lists other spell names that are prerequisites for a spell to be known; I want to display “(!)” after a any spell name of the prerequisite list for a spell, that is missing from the spellbook. (Note: the prerequisites are listed in plain text in the prerequisites
field of any spell, in the form of spell1 name, spell2 name, ..., spelln name
)
I’m trying to do that through the following segment:
<$let prereq={{{ [<spell>get[prerequisites]] }}}><$list filter="[<prereq>split[, ]]" variable="segm" join=", "><$link to=<<segm>>/><% if ![[<spellbook>indexes[]]contains[<segm>]] %>
(!)<% endif %></$list></$let>
But I’m getting “(!)” after every spell in the prerequisites even when they are listed in the spellbook. In the image below featuring the rendered character tiddler, the (!) that should not be there are circled in red:
Evidently,
<% if ![[[<spellbook>indexes[]]contains[<segm>]] %>
(!)<% endif %>
… doesn’t work like I’m expecting it to.
Can any TW tenor point me in the right direction? Is it indeed a syntax mistake, or the segmenting of the listing process through macros and stuff that gives me this unwanted behaviour?
Thanks in advance for all help and suggestions provided