Converting Classic Plugins to TW5, specifically responding to a button click in code

132 views
Skip to first unread message

Robbie Matthews

unread,
Oct 8, 2019, 6:56:44 PM10/8/19
to TiddlyWikiDev
A friend of mine has spent quite a lot of time with a Classic Tiddlywiki, and keeps all his roleplaying stuff on it.

However, he's got to the point where he can no longer apparently save anything on his linux box, so I started looking at setting up a node.js server for him/.

His stuff relies heavily on two plugins. One of which is Rollon, a plugin for rolling randomly on tables : http://rollon.tiddlyspot.com  The other for is an extension to this that I wrote for him.

I've got fairly decent JS chops so I'm happy to rewrite, but so far I've been having a very hard time with the plugin development docs, which appear to assume you already know how the new plugin structure works, and how to write a plugin.

So, 

a) I want to replicate the functionality of rollon. It doesn't need to be a plugin per se, I'm happy with any approach that will work.

b) I want to have a macro build a button that I can then respond to when it is clicked. The event should include enough information to work out which tiddler it is coming from. I should be able to attach a few addition fields to the button so I can interrogate it later.

c) I'm puzzled by the /*\ */\ structure I'm seeing at the top of a lot of example code... is this a node.js  thing or is it specific to tw?

d) Ditto, I'm puzzled by precisely how the "export" var works... again, is this a node.js thing?

e) What are the different module-types, and where are they documented?

Any help appreciated. 

PS: Experienced programmer, pretty solid JS chops, but node.js is still new ground for me.  And TW5 is wildly different internally from classic.




-

TonyM

unread,
Oct 8, 2019, 8:48:52 PM10/8/19
to TiddlyWikiDev
Robbie,

I believe this is all possible with wikitext and macros. 
  • Could you define the functionality you want without reference to the history. I followed your example and its hard to understand what rollon is. And the previous implementation seems to be something we can improve on.
  • Can you describe what you want independently from the way to achieve it?
  • I would not be surprised if better solutions already exist.
I will try and provide a solution if I understand the problem.

Regards
Tony

Robbie Matthews

unread,
Oct 8, 2019, 9:16:05 PM10/8/19
to tiddly...@googlegroups.com
Basically, if you include the macro <<rollon Monsters>>, the plugin did one of two things:
If the page is tagged "rollonResult":
*  Look up the selected named tiddler (ie, "Monster") and randomly selects an entry from a list stored as a tiddler. The list can have variable probabilities, 
Otherwise: 
* Render a button that, when clicked, produces a new tiddler tagged with "rollonResult",  with a <<rollon>> tag, so that it renders the result as a new tiddler.

I'm trying to come up with something that can produce the same, or at least a similar, result. This represents quite a lot of work over years for my friend, and I want to avoid rewriting his entire wiki.

At the same time, this does not need to be packaged in any way, it's pretty much a one-shot thing. I may package it up as a plugin later, but first I just need to find a solution. 



Virus-free. www.avast.com

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/ce10b804-c2bc-4146-b091-cda5f8790f5c%40googlegroups.com.


--

Beginning Android Tablet Programming

  • Publication Date: November 2, 2011
  • ISBN13: 978-1-4302-3783-9

Robbie Matthews gives a full, no-holds barred introduction to Android  programming for tablets. No previous experience required! Learn More …

Beginning Android Tablet Programming


Virus-free. www.avast.com

TonyM

unread,
Oct 9, 2019, 1:22:45 AM10/9/19
to TiddlyWikiDev
Robbie,

This can all be achieved with wiki text, widgets and macros in tiddlywiki5. In fact it is bread and butter stuff, no plugins. I would offer to do it but I have spent too much time on tiddlywiki today. I hope others can help

Some quick directions
If the page(tiddler?) is tagged "rollonResult":
Use a tiddler tagged  $:/tags/ViewTemplate containing something like this
<$list filter="[all[current]tag[rollonResult]]" variable=null>

here what ever your want to do on tiddlers tagged
rollonResult

</$list>

*  Look up the selected named tiddler (ie, "Monster") and randomly selects an entry from a list stored as a tiddler. The list can have variable probabilities, 

There are multiple ways to do this and I would redefine what you want, rather than putting it in terms needed within twc. Lists can be tagged or in a data tiddler, or in a list field (as a result of tagging)

There are some recently discussed random tiddler solutions
 
Otherwise: 
* Render a button that, when clicked, produces a new tiddler tagged with "rollonResult",  with a <<rollon>> tag, so that it renders the result as a new tiddler.



I'm trying to come up with something that can produce the same, or at least a similar, result. This represents quite a lot of work over years for my friend, and I want to avoid rewriting his entire wiki.

You can get much of what was done in TWC much more easily. Once you grasp the new methods.
 
Regards
Tony

Robbie Matthews

unread,
Oct 9, 2019, 2:53:22 AM10/9/19
to TiddlyWikiDev
Thanks...


On Wednesday, 9 October 2019 16:22:45 UTC+11, TonyM wrote:
Robbie,

This can all be achieved with wiki text, widgets and macros in tiddlywiki5. In fact it is bread and butter stuff, no plugins. I would offer to do it but I have spent too much time on tiddlywiki today. I hope others can help

Some quick directions
If the page(tiddler?) is tagged "rollonResult":
Use a tiddler tagged  $:/tags/ViewTemplate containing something like this
<$list filter="[all[current]tag[rollonResult]]" variable=null>

here what ever your want to do on tiddlers tagged
rollonResult

</$list>

I'm not convinced you've  quite grasped what I'm trying to do, as I can't see how that will help. Could you possibly unpack that a little more? ie, "here what ever you want to do..." is where the documentation keeps leaving off. I don't know what I CAN do.


*  Look up the selected named tiddler (ie, "Monster") and randomly selects an entry from a list stored as a tiddler. The list can have variable probabilities, 

There are multiple ways to do this and I would redefine what you want, rather than putting it in terms needed within twc. Lists can be tagged or in a data tiddler, or in a list field (as a result of tagging)

There are some recently discussed random tiddler solutions
 
Otherwise: 
* Render a button that, when clicked, produces a new tiddler tagged with "rollonResult",  with a <<rollon>> tag, so that it renders the result as a new tiddler.


I was beginning to think that would solve at least part of the problem. 

What is the actual difference between sending message tm-new-tiddler, and ActionCreateTiddler?
 



You can get much of what was done in TWC much more easily. Once you grasp the new methods.

But I can't seem to find very much detail about what the new methods are, which is part of my issue.

Again, any help appreciated.

 

PMario

unread,
Oct 9, 2019, 7:52:19 AM10/9/19
to TiddlyWikiDev
Hi Robbie,

There is the tiddlywiki dev edition, that may give you a good starting point about the internal tw structure.


-m

PMario

unread,
Oct 9, 2019, 7:59:12 AM10/9/19
to TiddlyWikiDev
On Wednesday, October 9, 2019 at 12:56:44 AM UTC+2, Robbie Matthews wrote:

c) I'm puzzled by the /*\ */\ structure I'm seeing at the top of a lot of example code... is this a node.js  thing or is it specific to tw?

These are special markers, that are needed, because internally TW uses the commonjs module handling mechanism. ... commonjs was developed for nodejs. ... but TW file based app, uses a completely "internal" module system, without any external files. see: https://tiddlywiki.com/dev/#Module%20System
 
d) Ditto, I'm puzzled by precisely how the "export" var works... again, is this a node.js thing?

 
e) What are the different module-types, and where are they documented?

PMario

unread,
Oct 9, 2019, 8:07:11 AM10/9/19
to TiddlyWikiDev
On Wednesday, October 9, 2019 at 12:56:44 AM UTC+2, Robbie Matthews wrote:

e) What are the different module-types, and where are they documented?

Any help appreciated. 

Jeremy did a lot of hangouts at the early days. This one may be of interest. It talks about the internal structure


have fun!
mario

TonyM

unread,
Oct 9, 2019, 6:21:49 PM10/9/19
to TiddlyWikiDev
Robbie,

So to be clear. You have a number of lists with a set number of values, perhaps we could call these sides of a N sided dice. You want a click to randomly select one of these sides.

Then in your case you want this to result in the creation of a tiddler "dicename (N)"  containing the random value, in effect rolling the dice?

If I am on target here, I think a more generalise solution, select a random item from a named list would be the best first step. It would them be trivial to add additional action widgets to translate the result into a new tiddler. 

If I may be so direct as to suggest I think you main barrier is learning more about tiddlywiki (Without thinking about Javascript) because if you knew it I think you would find your solution quite easily. In the meantime If you want me or others to provide a solution you may need to state your need logically and spell out your needs.

However, perhaps the quickest approach is to ask such question in this forum https://discord.gg/ehFSnV frequented by gamers, who may have solved this before.


I am offering to provide a solution, just ask, but treat me as ignorant and spell it out.

Regards
Tony

On Wednesday, October 9, 2019 at 9:56:44 AM UTC+11, Robbie Matthews wrote:

Robbie Matthews

unread,
Oct 9, 2019, 6:59:14 PM10/9/19
to TiddlyWikiDev
I think I've got enough of a handle on this now to do what I want to do. I think button and ActionCreateTiddler do a lot of what I need for the button mechanism, and I've now worked out how to access most of what I want to access.

I have a question: Most of the plugin/macro code I've looked at uses the structure
/*\ Some information \*/

Do the "\" do anything, or is it a purely a stylistic thing?

TonyM

unread,
Oct 9, 2019, 11:34:10 PM10/9/19
to TiddlyWikiDev
I am confident it is stylistic unless its used somehow to extract the content programmatically (unlikely)

Typically 
\something\
 is not used ever, except for a recently discovered hack with regex in operators.

/* commenting is common */

Regards
Tony

PMario

unread,
Oct 10, 2019, 3:04:34 AM10/10/19
to TiddlyWikiDev
On Thursday, October 10, 2019 at 5:34:10 AM UTC+2, TonyM wrote:
I am confident it is stylistic unless its used somehow to extract the content programmatically (unlikely)

It is needed. It is a marker to extract the header info for .js core tiddlers at startup.

-m

Robbie Matthews

unread,
Oct 11, 2019, 6:28:30 AM10/11/19
to TiddlyWikiDev
Is this documented anywhere? I've noticed it does not seem to be required for user macro modules.

Robbie Matthews

unread,
Oct 11, 2019, 8:15:58 PM10/11/19
to TiddlyWikiDev
In any case, I've managed the conversion to my satisfaction, and made some notes which may help others.

Yakov

unread,
Oct 25, 2019, 3:03:31 AM10/25/19
to TiddlyWikiDev
Hi Robbie,

let me note that there are solutions based on node and not only that for TWC:
In case your friend is interested in some help with TWC, you are welcome at TWC GG.

Best regards,
Yakov.

среда, 9 октября 2019 г., 1:56:44 UTC+3 пользователь Robbie Matthews написал:

Robbie Matthews

unread,
Oct 28, 2019, 12:21:58 AM10/28/19
to tiddly...@googlegroups.com
The issue was more to do with the fact that most solutions required updating from TW classic, which in turn required porting the plugins across. 
Once I worked out that what I wanted was a macro and not a plugin, it was pretty easy.  (Also understanding how self calling function definitions worked also helped)

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages