[tw5] How to get simple i=i+2 in wiki macros?

Hi! I write a simple macros on https://tiddlywiki.com/

<$vars a=0>
<$list filter="[tag[TableOfContents]]">
<$vars a={{{[add[2]]}}}> <></$vars> <>

</$list>
</$vars>

and I see this

2 HelloThere
2 Learning
2 Working with TiddlyWiki
2 Customise TiddlyWiki
2 Features
2 Languages
2 Editions
2 Plugins
2 Platforms
2 Reference
2 Community
2 About

but I want to see this

2 HelloThere
4 Learning
6 Working with TiddlyWiki
8 Customise TiddlyWiki
10 Features
12 Languages
14 Editions
16 Plugins
18 Platforms
20 Reference
22 Community
24 About

where is my mistake?

1 Like

Hi,

It looks like you are treating TiddlyWiki and widgets like a programming language, trying to do iteration in each loop. That doesn’t work.

Take a look at the “counter” attribute in list widget. That is a relatively new feature to help handle what you are doing.

To get the desired output:

<$list filter="[tag[TableOfContents]]" counter=“a”>
<$text text={{{ [multiply[2]]}}}/> <>

</$list>

Thank you Cj. And how can we get this list?
1 HelloThere
1Learning
1 Working with TiddlyWiki
2 Customise TiddlyWiki
2 Features
2 Languages
3 Editions
3 Plugins
3 Platforms
4 Reference
4 Community
4 About

воскресенье, 28 ноября 2021 г. в 21:25:00 UTC+3, cj.v...@gmail.com:

Use this calculation: <$text text={{{ [<a>subtract[1]divide[3]trunc[]add[1]] }}}/>

enjoy,

-e