action setfield surprise

119 views
Skip to first unread message

Jean-Pierre Rivière

unread,
Apr 23, 2021, 11:22:25 AM4/23/21
to TiddlyWiki
Hi!

I found out that to update to 42 the value of field "bar" in tiddler "foo" I *must* use the syntax

<$action-setfield $tiddler=foo bar=42/>

and that the following has no effect that I cam see:

<$action-setfield $tiddler=foo $field=bar $value=42/>

although I would have thought both as valid from reading the doc.

Is that normal (under tw5.1.23)? What does achieve the second form?

Jeremy Ruston

unread,
Apr 23, 2021, 11:30:21 AM4/23/21
to tiddl...@googlegroups.com
Hi Jean-Pierre

In my quick test creating a new tiddler on tiddlywiki.com/prerelease and entering the following, and then clicking the button, everything worked as expected.

<$button>
<$action-setfield $tiddler="HelloThere" $field=bar $value=42/>
test
</$button>

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/a13a6c5f-6cb1-46f5-a059-77999f19305en%40googlegroups.com.

Jean-Pierre Rivière

unread,
Apr 23, 2021, 1:03:20 PM4/23/21
to TiddlyWiki
Yes. Fine !!!

But on my 5.1.23, it seems to be tgat the action of $action-setfield is not immediate but postponed to the end of the action (ie when the matro called by actions=<<my-macro>> has terminated).

This is problematic for me as I was trying to increment a value within a loop by using  $action-setfield in an action setup.

I have tried my code on your new wiki, but I can't make it function in any way. I don't know why yet. I'm waiting for your answer about the moment when the field modification take place before trying anew (it might not be useful...)

regards

Jean-Pierre Rivière

unread,
Apr 23, 2021, 3:14:37 PM4/23/21
to TiddlyWiki

I simplified my test.

Definitely, the update is postponed. And also, the updating mechanism is nos broken in 5.1.23, it was a mistake of mine because of what I report here below.

demo code:
====
\define just-do-it()
<$set name=seen filter="[<target>get<dest>]">
<$action-log $$message="before update" $$filter="target dest seen"/>
</$set>
<$action-setfield $tiddler=<<target>> $field=<<dest>> $value=<<foo>>/>
<$set name=seen filter="[<target>get<dest>]">
<$action-log $$message="after update" $$filter="target dest seen"/>
</$set>
\end

<$vars target="Community" dest=ndx>
<$set name=foo value=1848>
<$button actions=<<just-do-it>>>
set <<foo>> into <<target>>!!<<dest>>
</$button>
</$set>
<$set name=foo value=1789>
<$button actions=<<just-do-it>>>
set <<foo>> into <<target>>!!<<dest>>
</$button>
</$set>
<br>current value: <$transclude tiddler=<<target>> field=<<dest>>/>
<br>See <$link to=<<target>>/>
</$vars>
====

see screen capture showing the console output!

update-field.png

Mohammad Rahmani

unread,
Apr 23, 2021, 3:21:23 PM4/23/21
to tiddl...@googlegroups.com
Both of these in TW 5.1.23 work fine!

Something goes wrong in your side!

Best wishes
Mohammad


Saq Imtiaz

unread,
Apr 23, 2021, 3:39:20 PM4/23/21
to TiddlyWiki
The sequence of execution of action widgets within a single block/string is not guaranteed. Therefore you cannot reliably set a value in  an action-widget and read it in a subsequent one if they are part of the same block of action widgets which have the same trigger. This is a known design limitation of the action-widget implementation.

You can work around this in limited situations with the Button widget by executing some actions in the body of the button and others in the actions attribute. Otherwise for things like having a counter, recursive macros are an option.



Jean-Pierre Rivière

unread,
Apr 23, 2021, 4:50:00 PM4/23/21
to TiddlyWiki
I had tested my stuff in the upcoming 5.1.24 online as the screen capture show.

With the latest pieces of information you gave, I can see that there can be a reason of my code failure. This is relief.

I have the decided to have a go at variables updating themselves, to see what it can do. Here is my test code:
====
\define just-count()
<$set name=z value="42">
<$action-log $$message="1." $$filter=z/>
<$set name=z1 value="z1=<<z>>">
<$set name=z filter="[<z>add[3]]">
<$action-log $$message="2." $$filter=z/>
<$set name=z2 value="z2=<<z>>">
<$set name=z filter="[<z>add[12]]">
<$action-log $$message="3." $$filter=z/>
<$set name=z3 value="<<z1>> ; <<z2>> ; z3=<<z>>"/>
<<z3>>
<$action-log $$message=<<z3>>/>
</$set></$set></$set></$set></$set></$set>
\end

\define only-count()
<$set name=z value="42">
<$set name=z1 value="z1=<<z>>">
<$set name=z filter="[<z>add[3]]">
<$set name=z2 value="z2=<<z>>">
<$set name=z filter="[<z>add[12]]">
<$set name=z3 value="<<z1>> ; <<z2>> ; z3=<<z>>">
only-count: <<z3>>
</$set></$set></$set></$set></$set></$set>
\end

\define wiki-count()
<$set name=z value=42>
<$wikify name=z1 text="z1=<<z>>">
<$set name=z filter="[<z>add[3]]">
<$wikify name=z2 text="z2=<<z>>">
<$set name=z filter="[<z>add[12]]">
<$wikify name=z3 text="<<z1>> ; <<z2>> ; z3=<<z>>">
wiki-count: <<z3>>
</$wikify></$set></$wikify></$set></$wikify></$set>
\end

<$button actions=<<just-count>>>
just count (see console)!</$button>
<br><<only-count>>
<br><<wiki-count>>
======

output in tiddler:
only-count: z1=57 ; z2=57 ; z3=57
wiki-count: z1=42 ; z2=45 ; z3=57

summarized output in console if button pressed:
1. z=42
2. z=45
3. z=57

with the button, it's fine but is there a problem with the number of closing </$set> or is a single one just fine? (not in the context of my code, but it could be the case if I was not defining z1, z2 and z3 in just-count macro)

without the button, we can see that the transitional values of z must be captured, hence my using the wikify widdget. Otherwisi all occurrence of z have the final value. I'm pretty sure this is a feature, not a bug, isn't it?

This being said, I will have a try at recursion and report here.
Reply all
Reply to author
Forward
0 new messages