Comparing integers to trigger conditional text; am I missing something?

Hello again!

As part of the rendering of a table listing of Spells which are stored in a dictionary tiddler that I call a “spellbook” where key/value pairs are of the form:

Spell name1:levelvalue
Spell name2:levelvalue
...
Spell name n:levelvalue

… I’m using a conditional to render a special button indicating if any of the spell entries of the dictionary tiddler are missing Prerequisites; each spell has its own descriptive tiddler, with a field called Prerequisites listing them one after the other separated by , . Those prerequisites can be other spells, or an advantage called “Magery” that has its own level; certain spells require the Magery level to be greater or equal than a certain value.

The Magery advantage itself is listed in a separate dictionary tiddler that I call an “advbook”, listing the advantages and their levels, using the same structure and format as the spellbook dictionary tiddler. I wrote the conditional as follows:

<% if [<advbook>getindex[Magery]compare:integer:lt[<segm>split[ ]last[]]] %>&nbsp;<$button class="tc-btn-invisible tc-tiddlylink mark negative" tooltip="Prerequisite is missing">{{$:/core/images/warning}}</$button>&nbsp;(your Magery: <$text text={{{ [<advbook>getindex[Magery]] }}}/>)<% endif %>

… Expecting that its contents would only display if the Magery level (retrieved through <advbook>getindex[Magery]) was lower than the Magery level required by the spell (retrieved through <segm>split[ ]last[]] because it would be written as “Magery X” in the advbook, X being the Magery level held as an advantage).

However, the contents of the conditional are always displayed regardless of the level of Magery.

Here is an indented and commented version of the whole code containing this conditional above for context and easier reading (all the other elements of that code work perfectly well):

<$list filter="[<prereq>split[, ]]" variable="segm" join=", ">
	<% if [<spell>has[prerequisites]] %> <!-- if spell has prerequisites -->
		<% if [<segm>regexp[^Magery \d+]]%> <!-- check if Magery is in its prerequisites -->
			<$list filter="[<segm>split[ ]]" variable="mageryseg" join=" ">
				<% if[<mageryseg>regexp[^Magery]] %><$link to="Magery"/>&nbsp;
				<% else %>''<<mageryseg>>''
				<% endif %>
			</$list>
			<$let advbook={{!!advbook}}> 
			  <% if [<advbook>!has:index[Magery]] %><!-- check if advbook is missing Magery -->
			  &nbsp;<$button class="tc-btn-invisible tc-tiddlylink mark negative" tooltip="Prerequisite is missing">{{$:/core/images/warning}}</$button>
			  <% else %> <!-- check if Magery advantage level is lower than required Magery level -->
				<% if [<advbook>getindex[Magery]compare:integer:lt[<segm>split[ ]last[]]] %>&nbsp;<$button class="tc-btn-invisible tc-tiddlylink mark negative" tooltip="Prerequisite is missing">{{$:/core/images/warning}}</$button>&nbsp;(your Magery: <$text text={{{ [<advbook>getindex[Magery]] }}}/>)
				<% endif %> 
			  <% endif %>
			</$let>
		  <% else %><!-- check if spellbook is missing the required spell -->
			<$link to=<<segm>>/>
			<% if [<spellbook>!has:index<segm>] %>&nbsp;<$button class="tc-btn-invisible tc-tiddlylink mark negative" tooltip="Prerequisite is missing">{{$:/core/images/warning}}</$button>
			<% endif %>
		  <% endif %>
		<% else %>
		  –
		<% endif %>
</$list>

Can someone tell what I’m missing that explains this unwanted behavior? Thanks in advance to all helpers :slight_smile:

In general, filter operand values cannot use nested filter syntax.

Specifically, the operand value for the compare:integer:lt[...] is supposed to be a number or a reference to a variable that contains a number.

To achieve your desired result, you need to separately calculate the Magery level value, and then reference it in the compare:integer:lt filter as a variable operand, like this:

<$let mageryvalue={{{ [<segm>split[ ]last[]] }}}>
<% if [<advbook>getindex[Magery]compare:integer:lt<mageryvalue>] %>...<% endif %> 
</$let>

-e

1 Like

Thanks again. That’s… very important to know :slight_smile: