How do I get the "max" of a math formula?

I have the following text:

<$set name="mods" value="
[[somatic]]
[[Permanent]]
[[Increased Range 5x]]
">
Modifiers: <$text text={{{ [enlist<mods>get[cost]sum[] }}}/>%

Final Cost: <$text text={{{ [enlist<mods>get[cost]sum[]add[100]divide[100]multiply{!!initial-cost}ceil[]] }}}/>

“Modifiers” is the sum of the “cost” fields of the various “mods” listed in the tiddler. This displays a number, usually between -80% and +200%.
It then calculates the “Final Cost” with this formula: FinalCost = RoundUp(InitialCost * (100 + Modifiers))

This is all working well (again, thanks to everyone here on the board Trying to understand syntax)
But I need to be able to limit the Modifers to -80% and above.

How can I modify:
[enlist<mods>get[cost]sum[]add[100]divide[100]multiply{!!initial-cost}ceil[]]
so that
get[cost]sum[]
Is limited to -80 or greater. max[] doesn’t seem to be the solution.

FYI, Here is a working example of the “Spell Book”: Spells Tiddlywiki — "Magic as Powers"

It works very well. It is very easy to create a spell. Here is an example:

{{||NotesTemplate}}
With a quick flick of their hand, the caster touches an item and binds the projection of a minor fire elemental to it.   The item emits a bright white-ish yellow light that covers a 10 yd radius circle.   Beyond that, the light dims, and it is harder to see.   The light lasts for an hour, or until the caster releases the elemental binding. <hr>
<$set name="mods" value="
[[somatic]]
[[Permanent]]
[[Increased Range 5x]]
">
{{||SpellTemplate}}
</$set>

And since I am using the “edit-comptext” plugin, the editor will auto suggest the names of modifiers as I type them in, and the instant preview shows me the running costs, so I can play “what if” scenarios.

Are you sure about that? Try using max[-80] in your final cost filter, like this:
[enlist<mods>get[cost]sum[]max[-80]add[100]divide[100]multiply{!!initial-cost}ceil[]]

-e

That is the first thing I tried:

<$text text={{{ [enlist<mods>get[cost]sum[]max[-80] }}}/>% ]
<$button>
   Final Cost: <$text text={{{ [enlist<mods>get[cost]sum[]max[-80]add[100]divide[100]multiply{!!initial-cost}ceil[]] }}}/>

But that displays:
[ Filter error: Missing [ in filter expression% ]

And then I found it. I was missing the second “]”.

<$text text={{{ [enlist<mods>get[cost]sum[]max[-80] ] }}}/>% ]

Thank you for making me look again. I tried it a few times… and kept getting that error message, and I kept looking for missing “[” and not “]” :slight_smile:

That is has a missing or misplaced “]”
<$text text={{{ [enlist<mods>get[cost]sum[]max[-80]] }}}/>%