I need anybody who knows about javascript macros to lay their eyeballs on the code below.
As much as I dislike javascript, sometimes there just doesn’t seem to be any choice but to go there. The javascript is easy: copy paste from wherever whatever is needed.
Having a tendency to avoid javascript as if it was like the plague, I don’t particularly want to learn the mechanics of creating javascript macros in TiddlyWiki.
For the code below, I just copied now.js and setup the javascript I needed. Seems to work A-1, but I’d like to know if there is anything wise for me to change (i.e. “infrastructure” stuff re TiddlyWiki and javascript macros.) Let’s not think for a second that I have any clue what I’m doing…
If you have a moment to scrutinize the following, THANK-YOU !!!
/*\
title: Random Number
type: application/javascript
module-type: macro
Macro to return a random number
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "random";
exports.params = [
{name: "maxvalue"}
];
/*
Run the macro
*/
exports.run = function(maxvalue) {
return Math.floor(Math.random() * maxvalue)+1;
};
})();
Thanks, but it isn’t the javascript I need checking. As long as the javascript works, and it does, then I’m fine.
It is all of the other stuff wrapped around the javascript to have a TiddlyWiki javascript macro. I really have no clue if any of it is okay, and that is way too much for me to know intimately.
Does this macro comply with the way we write a javascript macro for use in tiddlywiki?
I think the answer may lay deep in the documentation about plugin development, but a simple answer will help Charlie (indirectly also me).
There is whole suit of simple macros that can be written that just make use of simple Javascript functions to obtain a result. Charlies being an example of one. If more of us knew how to and did so without breaking things, it would be helpful.
@Charlie_Veniot Perhaps you would get more attention for this in the developer Category or on Github discussions?.