Hello all,
I have the created a procedure to calculate a bonus/malus from a skill
stored as a key in a spellbook
dictionary tiddler. The logic is a bit cumbersome:
- skills have Easy, Average, Hard or Very Hard difficulties, stored for each of them in their
difficulty
field - the skillbook only references the name of its skills as keys, and the amount of cp (Character points) invested in them as values, in the form
skill name:cp invested
- Depending on their diffculty, the bonus/malus varies depending on them, but not linearly or geometrically
This bonus/malus follows the table below (Attribute is irrelevant for my current needs, I only need the bonus/males value, like “-3”, “-2”, “0”, “1”, “4”, etc.):
In any case, I reproduced the logic of the table in the procedure, but my <$text>
widgets fail to return the expected calculation result, and seem to return a blank; any condition that uses a plain number (negatives in this case) works perfectly fine.
\procedure rel-lvl-value(skillbook, skill)
<% if [<skillbook>!has:index[<skill>]]
(<<skill>> not in <<skillbook>>)
<% else %>
<$let cp={{{ [<skillbook>getindex<skill>] }}} difficulty={{{ [<skill>get[difficulty]] }}}>
<% if [<difficulty>match[VH]] %>
<% if [<cp>compare:eq[1]] %>
-3
<% elseif [<cp>compare:eq[2]] %>
-2
<% else %>
<$text text={{{ [[<cp>]divide[4]trunc[]substract[2]] }}} />
<% endif %>
<% elseif [[<skill>get[difficulty]]match[H] %>
<% if [<cp>compare:eq[1]] %>
-2
<% elseif [<cp>compare:eq[2]] %>
-1
<% else %>
<$text text={{{ [[<cp>]divide[4]trunc[]substract[1]] }}} />
<% endif %>
<% elseif [[<skill>get[difficulty]]match[A] %>
<% if [<cp>compare:eq[1]] %>
-1
<% elseif [<cp>compare:eq[2]] %>
0
<% else %>
<$text text={{{ [[<cp>]divide[4]trunc[]] }}} />
<% endif %>
<% elseif [[<skill>get[difficulty]]match[E] %>
<% if [<cp>compare:eq[1]] %>
0
<% elseif [<cp>compare:eq[2]] %>
1
<% else %>
<$text text={{{ [[<cp>]divide[4]trunc[]add[1]] }}} />
<% endif %>
<% else %>
(Error: <<skill>> difficulty field doesn't match VH, H, A or E)
</$let>
<% endif %>
\end
I’d think I have a syntax issue in the text
parameter of the <$text>
widgets, but I can’t figure it out becaause it has worked in other cases (although they where macros and not procedures, perhaps). Is the mistake I’m making obvious to anybody?