Hello TW world and calculation question

103 views
Skip to first unread message

Brad DeBruler

unread,
Feb 23, 2021, 11:21:46 AM2/23/21
to TiddlyWiki
Hi everyone!

I just discovered TiddlyWiki last week via a reddit post on using it to organize D&D campaigns and was immediately struck by thousands of ideas all at once for using it.

I don't really have a coding background, though I have cobbled a few macros together in excel. Since I have been very excel centric, I was wondering how to do calculations and formulas in TW. At the moment I would like to do the following:

=INT(({{!!myfield}}-10)/2)

I don't assume there is an INT() function, so I'm kind of stuck.

Thanks in advance!

Eric Shulman

unread,
Feb 23, 2021, 11:39:29 AM2/23/21
to TiddlyWiki
On Tuesday, February 23, 2021 at 8:21:46 AM UTC-8 brad.d...@gmail.com wrote:
...how to do calculations and formulas in TW. At the moment I would like to do the following:
=INT(({{!!myfield}}-10)/2)

Calculations are done using the "filter" syntax.  There are several ways to do this.

* direct rendering using "filtered transclusion"
{{{ [{!!myfield}subtract[10]divide[2]trunc[]] }}}

* using the $set widget with "filter" parameter
<$set name="result" filter="[{!!myfield}subtract[10]divide[2]trunc[]]">

* using the $vars widget with filtered transclusion as a parameter
<$vars result={{{ [{!!myfield}subtract[10]divide[2]trunc[]] }}}>

Notes:
* within the filter syntax, field references use *single* curly braces.
* there isn't any filter syntax for using parentheses in calculations, so the order of operations is very important
* sometimes this means using several filters to calculate intermediate results and then combining them.

For example, to calculate something like this:
INT(({!!myfield} / 2) - ({!!myfield} - 5))

You could write:
<$vars part1={{{ [{!!myfield}divide[2]] }}} part2={{{ [{!!myfield}subtract[5]] }}}>
<$vars result={{{ [<part1>subtract<part2>trunc[]] }}}

enjoy,
-e

Ste

unread,
Feb 23, 2021, 1:22:29 PM2/23/21
to TiddlyWiki
You might also try this plugin for a more excel like expeiance. 

Brad DeBruler

unread,
Feb 23, 2021, 3:01:44 PM2/23/21
to TiddlyWiki
Thanks to both of you! I'll give these a try.

Mat

unread,
Feb 23, 2021, 3:21:28 PM2/23/21
to TiddlyWiki
Welcome Brad!

AFAICT, the INT function is the same as TiddlyWikis floor operator. (But floor also works on multiple numbers at once).

TW has quite a few math filter operators if you didn't see them already.

<:-)

Charlie Veniot

unread,
Feb 23, 2021, 10:10:38 PM2/23/21
to TiddlyWiki
Hey Brad, welcome to TiddlyWikiHood !!!
Reply all
Reply to author
Forward
0 new messages