How does the set widget actually work?

127 views
Skip to first unread message

Dave

unread,
Mar 1, 2017, 7:17:39 PM3/1/17
to TiddlyWiki
I've realized on another thread that I must have a fundamental misunderstanding of the set widget.  Isn't it supposed to set a variable for use elsewhere?

\define mymacro()
<$set name="result" value="Hi Bob"/>
<result>
$result$
$
(result)$
\end

<<mymacro>>

When I run the above macro, all I get is

$result$


I also tried it like this
<$set name="result" text="Hi Bob"/>

but got the same results.

I have got set widget to work in situations like this:
<$list filter="[<result>getindex[$testname$]]">

but not sure what the distinction is there (set variables only work inside widgets?)


Anyway, is there a correct way to get it to work the way I need? or perhaps is there an alternate widget to use?


(My ultimate goal is to get a result from inside one macro and transfer it to another macro for further processing.)

Thanks,
Dave




Mark S.

unread,
Mar 1, 2017, 8:14:13 PM3/1/17
to TiddlyWiki

Your macro should look like this:

\define mymacro()
<$set name="result" value="Hi Bob">
<<result>>
</$set>
\end

<<mymacro>>

You had a forward slash at the end of the <$set.../> tag. The value of the variable only "lives" between a set of tags, e.g. <$set ...></$set>. Since you didn't have a set of tags, the value ended before it was invoked.

You invoked "result" as <result>. Variables set by the setwidget get invoked with <<result>>. These are different than variables passed to the macro which get invoked like $result$.

It gets more confusing. If you had called <$set> before invoking the macro, then inside the macro definition you could use $(result)$, like this:

\define mymacro()
<$set name="result" value="Hi Bob">
<<result>>
$
(result)$
</$set>
\end

<$set name="result" value="Hi Doug">
<<mymacro>>
</
$set>


Which results in:

Hi Bob Hi Doug


HTHSH (Hope this helped somehow)

Mark

Dave

unread,
Mar 1, 2017, 8:21:30 PM3/1/17
to TiddlyWiki
Thanks!

(You must be from the Great White North, eh?)

Message has been deleted

Dave

unread,
Mar 1, 2017, 9:18:35 PM3/1/17
to TiddlyWiki
ok, so now how do I pass that on to another macro?

this doesn't work:

\define myothermacro(gddayeh)
$
gddayeh$
\end



\define mymacro()
<$set name="result" value="Hi Bob">
<<myothermacro  "<<result>>" >>
</$set>
\end

<<mymacro>>



Mark S.

unread,
Mar 1, 2017, 10:08:39 PM3/1/17
to TiddlyWiki
You need to invoke it differently. Like:

\define myothermacro(gddayeh)
$gddayeh$
\end

\define mymacro()
<$set name="result" value="Hi Bob">
<$macrocall $name=myothermacro  gddayeh=<<result>> />
</
$set>
\end

<<mymacro>>

To pass the value of the variable (BTW, I'm probably using the wrong term here) you need to pass it inside a widget (or at least that's how I understand it). The widget that runs macros is <$macrocall>. Note that the name of the macro is passed inside a dollar-variable ($name) and not "name". This is one of the inconsistencies that will drive you nuts.

Basically, macros, variables, parameters, arguments in TW5 aren't like anything you will see anywhere else. So don't feel bad if takes a while to make sense of it all.

Mark

Dave

unread,
Mar 1, 2017, 10:47:17 PM3/1/17
to TiddlyWiki
Thank you!
Reply all
Reply to author
Forward
0 new messages