[TW5] Get value of state tiddler field

155 views
Skip to first unread message

Tristan Kohl

unread,
Apr 4, 2017, 6:38:52 AM4/4/17
to TiddlyWiki
Hey guys,

it is me again. Still working on my website and coming up with another problem. I still can not completely wrap my head around how to achieve some simple - at least I think they are - things. I am writing a plugin for my site to track my beekeeping and therefore made a button which "creates" a new hive and increments a global counter.

However since this whole thing should be a plugin I do not want to store a "counter" within the sidebar tiddler containing the button but rather have a "state" tiddler handling this as there are a couple of things I want to increment (queens, hives, checks...). My problem is that I do not know how to "get" the value from the state tiddler in the first place so I can increment it and set the new value (increment macro does work).

As of now I have this (what do I have to insert at the question marks?):

<$button>New Hive
    <$set name="counter" value=<<increment ???>>>
        <$action-sendmessage $message="tm-new-tiddler" title=Hive #<<counter>> tags="active Hive" />
    <$action-setfield $tiddler="$:/state/beehive" $field="hiveCounter" $value=<<counter>> />
    </$set>
</$button>

Thanks in advance.
Cheers,
Tristan

Mat

unread,
Apr 4, 2017, 10:14:59 AM4/4/17
to TiddlyWiki
Hi Tristan

I'm probably misunderstanding something because you are clearly working with more advanced stuff than my answer here... but is this what you're missing:

{{statetiddler}} or possibly {{statetiddler!!somefield}}

<:-)

Mark S.

unread,
Apr 4, 2017, 10:37:34 AM4/4/17
to TiddlyWiki
I've never had any luck passing a <<macro>> with parameters to a widget. What I would do is use another <$set> widget before the existing set that would provide the increment value. For instance something like "incvalue" Then inside of <<increment>> refer to it as $(incvalue)$. It might look like ...

<$button>New Hive
<$set name="incvalue" value="3">
    <$set name="counter" value=<<increment>>>
        <$action-sendmessage $message="tm-new-tiddler" title=Hive #<<counter>> tags="active Hive" />
    <$action-setfield $tiddler="$:/state/beehive" $field="hiveCounter" $value=<<counter>> />
    </$set>
</$set>
</$button>

HTH
Mark

Tristan Kohl

unread,
Apr 4, 2017, 11:01:46 AM4/4/17
to TiddlyWiki
Hey guys,

thanks for your input on this.

@Mat: unfortunately your solution does not work, or I do not get where to put it^^

@Mark: Well I get where you going, but I do not understand where to put the $(incvalue)$ reference. My code looks like this at the moment:

<$button>New Hive
    <$set name="incval" value={{$:/state/beehive!!hiveCounter}}>
        <$set name="counter" value=<<calc value="1" by=<<incval>>>
            <$action-sendmessage $message="tm-new-tiddler" title=<<counter>> tags="active hive" />

            <$action-setfield $tiddler="$:/state/beehive" $field="hiveCounter" $value=<<counter>> />
        </$set>
    </$set>
</$button> 

As I fail explaining what I want to do, I like to link to Tobias' One Button Multiple Actions post which is very close to what I want. The only difference is that I want the counter to be from another tiddler (namely $:/state/beehive). I hope this makes things a little clearer, sorry...

Tristan

Tristan Kohl

unread,
Apr 6, 2017, 10:32:42 AM4/6/17
to TiddlyWiki
Mark,

after sleeping for a night and doing some other stuff I got what you meant and solved the issue in a similar way.
Thank you very much :)

Tristan Kohl

unread,
Apr 6, 2017, 10:34:51 AM4/6/17
to TiddlyWiki
If someone is interested in the solution I took, here is my (shortened) code:

<$button>Save new Hive
    <$set name="counter" value=<<calc $:/state/beehive!!hive-counter 1>>>
        <$set name="newTitle" value=<<format "Hive {0}" $(counter)$>>>
            <$action-setfield $tiddler=<<newTitle>> $field="hive-id" $value=<<counter>> />
        </$set>
    </$set>
</$button>

Reply all
Reply to author
Forward
0 new messages