I will show you my actual code. However, note that the problem is that the first evaluation (which happens alng the lines that @jeremyruston hinted, leads to a javascript error that stop the rendering with a big ugly dialog box of error! So my main concern is to avoid this to happen.
This is what, finally, was really different here than in my previous works. So this mean that I shall modify my code with a more defensive code, that would allow for an empty value to be gently ignored. And thus avoid my checking of existence before calling a macro just to avoid its code to be executed.
the triggering is dead simple:
<$button actions=<<setupRound 4>>>setupRound 4</$button>
the setupRound macro (original code without my later fix):
\define setupRound(roundid)
<$let
data = "$:/user/data"
tournmt = {{{ [<data>get[tournament]] }}}
where = {{{ [<data>addsuffix[/]addsuffix<tournmt>] }}}
roundTid = {{{ [<where>addsuffix[/round/$roundid$]] }}}
>
<$action-log $$message="setupRound($roundid$)" $$filter="roundTid"/>
<$macrocall $name=getPairingMethod roundid="$roundid$" targetTiddler=<<roundTid>> targetField=pairing/>
<$action-confirm $prompt=no>
<$action-log $$message="doSetupRound($roundid$)" $$filter="roundTid"/>
<$let pairMacro = {{{ [<roundTid>get[pairing]dump[read pairing]addsuffix[Pair]dump[pairMacro]] }}}>
<$macrocall $name=<<pairMacro>> roundid="$roundid$"/>
<$action-confirm $prompt=no>
<<writeOpp "$roundid$">>
<<writeEncounters "$roundid$">>
<$action-confirm $prompt=no>
<<checkOpp "$roundid$">>
</$action-confirm>
</$action-confirm>
<$action-log $$message="""pairing done for round $roundid$""" $$filter=roundTid/>
</$let>
</$action-confirm>
</$let>
\end
The getPairingMethod
macro will read data and write a field (here, pairing
) in a tiddler (here defined by the value of roundTid
). This field is the read by setupRound
to build the value of the pairMacro
variable, and this is that macro which is then called. Here what the sequentialPair
macro does (this is tha macro actually called):
\define sequentialPair(roundid)
<$action-log $$message="sequentialPair($roundid$)"/>
<<calcFreeOpp "$roundid$">>
<$action-confirm $prompt=no>
<<prepareSequentialPairing "$roundid$">>
<$action-confirm $prompt=no>
<$let
data = "$:/user/data"
tournmt = {{{ [<data>get[tournament]] }}}
where = {{{ [<data>addsuffix[/]addsuffix<tournmt>] }}}
prevRoundid = {{{ [[$roundid$]subtract[1]] }}}
freeopp = {{{ [<where>addsuffix[/freeopp/$roundid$]dump[freeopp tid]get[text]dump[freeopp]] }}}
roundTid = {{{ [<where>addsuffix[/round/$roundid$]dump[roundTid]] }}}
deepTally = {{{ [<where>addsuffix[/deepTally/]addsuffix<prevRoundid>] }}}
players = {{{ [<where>addsuffix[/players]] }}}
endOfline = {{{ [charcode[10]] }}}
pairs = {{{ [<deepTally>get[text]split<endOfline>dump[ranks]seqpair<freeopp>] }}}
>
<$action-log $$message="sequential _pair($roundid$)" $$filter="deepTally pairs players"/>
<$action-createtiddler $basetitle=<<roundTid>> $overwrite=yes round="$roundid$" type="application/x-tiddler-dictionary"/>
<$action-confirm $prompt=no>
<$list variable=next counter=num filter="[<pairs>split[;]!is[blank]]">
<$let table = {{{ [[t]addsuffix<num>] }}} >
<$action-setfield $tiddler=<<roundTid>> $index=<<table>> $value=<<next>>/>
<$action-log $$message="next table" $$filter="table next roundTid"/>
</$let>
</$list>
</$action-confirm>
<$action-log $$message="""sequential pairing written for round $roundid$""" $$filter=roundTid/>
</$let>
</$action-confirm>
</$action-confirm>
\end
The problem in real life is that the pairs
variable is immediately evaluated, before the tiddler whose name is the value of the freeopp
variable exists and the poor coding of my seqpair
filter operator throws a javascript error.
So from what I have seen so far, this is normal. I initially falsely thought that <$action-confirm>
would block the evealuation of <$let>
widgets after it, and was really confused.
Could such a blockage eventually exists later?
Anyway. I hope everything is now clear to you of what I was asking. I was hoping to be able to avoid such details.
(BTW all this code is from a tournament manager project of mine.)