[TW5] Setting a field for a list of tiddlers, incrementing for each one?

207 views
Skip to first unread message

Matthew Petty

unread,
Apr 18, 2016, 3:30:49 PM4/18/16
to TiddlyWiki
I have a set of tiddlers, and I want to set a field for each one, incrementing the value each time.

So for example, I have tiddlers A B C D, and after running this macro or whatever, they would have the following fields:
A would have 1
B would have 2
C would have 3
D would have 4

What would be the easiest way to do that?

Matthew Petty

unread,
Apr 19, 2016, 4:09:34 AM4/19/16
to TiddlyWiki
I've been looking at tobibeer's setvars plugin, to see if that would work, but I can't figure it out.

Here's some pseudocode for what I want to do.

set index to initial value
set increment amount
set required filter and sort

select list of tiddlers by the filter
for each tiddler
   
set field to index value
    increment index
by increment amount
next tiddler

Any help gratefully received

Hegart Dmishiv

unread,
Apr 19, 2016, 4:46:54 AM4/19/16
to TiddlyWiki
Hi Matthew,

I think TobiBeer's make[ ] filter plugin might be what you're looking for.

Hegart.

Matthew Petty

unread,
Apr 19, 2016, 5:01:33 AM4/19/16
to TiddlyWiki
I've looked at that, but it seems to be creating new tiddlers, and setting the titles. What I need is to take existing tiddlers and set a field.

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/S0CYsynRi7E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/8caaedbc-ba59-4c92-aa24-2b345048da1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hegart Dmishiv

unread,
Apr 19, 2016, 5:16:26 AM4/19/16
to TiddlyWiki
Hi Matthew,

Can I confirm, do you want the name of the field itself to be incremented, or the value within a given field to be incremented? From your examples above, it looks like you want the former, is that correct?

Hegart.

Matthew Petty

unread,
Apr 19, 2016, 5:57:16 AM4/19/16
to TiddlyWiki
Ah, no, apologies for the confusion. Here's what I want, in more detailed pseudocode (I'm probably using the wrong symbols):

set index=1
set increment_amount=1
set filter="[tag[this_tag]nsort[sort_order]]"

select list of tiddlers by <<filter>>
for each tiddler in list
   
set field 'sort_order' to <<index>>
    increment
<<index>>
by <<increment_amount>>
next tiddler



One issue that I can think of is that because the filter is using the field being changed, it may affect the list when it is changed.

-MJP

Matthew Petty

unread,
Apr 20, 2016, 9:40:18 AM4/20/16
to TiddlyWiki
Bump? Anyone?
I have the feeling that setvars would be useful, or calc, or action-setfield. But how to bring it together?
Message has been deleted

Hegart Dmishiv

unread,
Apr 20, 2016, 4:30:24 PM4/20/16
to TiddlyWiki
Hi Matthew,

Sorry, I was working on a solution to this yesterday, but I got sidetracked. Here's a demo I've been building. It's not complete yet, and the essential ingredient is still missing, so you might not even want to waste your time with it yet. I'll let you know if/when I solve it. In the meantime, if anyone else can come up with a solution, that'd be great.

Hegart.

Matthew Petty

unread,
Apr 21, 2016, 3:13:25 AM4/21/16
to TiddlyWiki
Hi Hegart,
Thank you for your efforts!
I took a look at your demo. I like the trick of using one tiddler with multiple fields for variables. Simple and elegant.

The calc plugin can be used to increment a value in a button (http://tobibeer.github.io/tb5/#calc). This increments by the incrementer value:

<$button set="$:/_Data/variables!!current-count" setTo=<<calc $:/_Data/variables!!current-count + by:$:/_Data/variables!!incrementer>>>+</$button>

So that is now a part of the pseudocode:

<$edit-text tiddler="$:/_Data/variables" field="current-count" size="5" />
<$edit-text tiddler="$:/_Data/variables" field="incrementer" size="5" />
<$edit-text tiddler="$:/_Data/variables" field="filter" size=50 />

<$list filter={{$:/_Data/variables!!filter}}>

for
each tiddler in list
   
set field 'sort_order' to <<
current-count>>
    increment
<<
current-count>> by <<incrementer>>
next tiddler


It's a question of triggering an action inside a list, in such a way as to make it act like a "for" loop.

-Matthew

Hegart Dmishiv

unread,
Apr 21, 2016, 3:50:08 AM4/21/16
to TiddlyWiki
Hi Matthew,

I can't seem to get the <<calc>> macro to work at all. The only thing it seems to do for me is to delete whatever field I point it at.

Hegart.

Matthew Petty

unread,
Apr 21, 2016, 3:56:47 AM4/21/16
to tiddl...@googlegroups.com
It's a plugin by tobibeer. I have no problems with it - strange

Reply all
Reply to author
Forward
0 new messages