In order to pass a value "by reference" to a macro call (while not inside a 
macro definition), you need to expand it out to the full <$macrocall> 
widget:
```
<$set name=bgcol value="7">
<div style=<<nowandthen m:11 v:2>>>
  <$macrocall $name=nowandthen m=11 v=<<bgcol>> />"<<bgcol>>"
</div>
</$set>
```

https://tiddlywiki.com/#MacroCallWidget

Best,
Joshua Fontany

On Friday, May 22, 2020 at 5:27:07 PM UTC-7, leeand00 wrote:
>
> Okay, so the $()$ syntax can only be used within a macro...gotcha;  Thanks!
>
> On Friday, 22 May 2020 19:31:07 UTC-4, Mark S. wrote:
>>
>> The substitution forms (e.g. $variable$, $(external variable)$ only work 
>> INSIDE a macro. So you have to 
>> put 
>>
>> <div style=<<nowandthen m:11 v:2>>><<nowandthen m:11 v:"$(bgcol)$">
>> >"$(bgcol)$"</div>
>>
>> inside its own macro like:
>>
>> \define misnamedmacro() 
>> <div style=<<nowandthen m:11 v:2>>><<nowandthen m:11 v:"$(bgcol)$">
>> >"$(bgcol)$"</div>
>> \end
>>
>> and call it:
>>
>>
>> <$set name=bgcol value="7">
>> <<misnamedmacro>>
>> </$set>
>>
>> Of course, there could be other things inside the JS macro that are 
>> wrong, but that's what's wrong out of the box.
>>
>> Good luck!
>>
>>
>>
>>
>> On Friday, May 22, 2020 at 4:01:24 PM UTC-7, leeand00 wrote:
>>>
>>> Hi, 
>>>
>>> I'm trying to pass a value to a variable to a javascript macro I'm 
>>> trying to write; the result keeps coming back NaN, and I belive it is 
>>> because I am passing "$(bgcol)$" instead of "7" for v:
>>>
>>> Is there some other way I ought to be passing this argument? 
>>>
>>> <$set name=bgcol value="7">
>>> <div style=<<nowandthen m:11 v:2>>><<nowandthen m:11 v:"$(bgcol)$">
>>> >"$(bgcol)$"</div>
>>> </$set>
>>>
>>> /*\
>>> title: $:/core/modules/macros/nowandthen.js
>>> type: application/javascript
>>> module-type: macro
>>>
>>> Macro to return a formatted version of the current time
>>>
>>> \*/
>>> (function(){
>>>
>>> /*jslint node: true, browser: true */
>>> /*global $tw: false */
>>> "use strict";
>>>
>>> /*
>>> Information about this macro
>>> */
>>>
>>> exports.name = "nowandthen";
>>>
>>> exports.params = [
>>>  {name: "m"},
>>>  {name: "v"}
>>> ];
>>>
>>> /*
>>> Run the macro
>>>
>>> m: is the highest value in the data set.
>>> v: is the value to render.
>>> */
>>> exports.run = function(m, v) {
>>>
>>>  let out = "background-color: rgb(";
>>>
>>> try {
>>>  m = parseFloat(m);
>>>  v = parseFloat(v);
>>>  console.log("m:" + typeof(m));
>>>  console.log("m:" + m);
>>>  console.log("v:" + typeof(v));
>>>  console.log("v:" + v);
>>>  let huh = v/m;
>>>  let where = huh*255;
>>>  console.log("huh: " + typeof(huh));
>>>  console.log("huh: " + huh);
>>>  console.log("where: " + typeof(where));
>>>  console.log("where: " + where);
>>>
>>> } catch(e) {
>>>  console.log("error: " + e);
>>> }
>>>
>>>  for(var i =0; i < 3; i++) {
>>>  let wha = ((parseFloat(v)/parseFloat(m)));
>>>  out = out + (Math.floor(wha*255)) + ", ";
>>>  }
>>>
>>>  out = (out.slice(0,-2)) + ");color:rgb(150,150,150);";
>>>
>>>  return out;
>>> };
>>>
>>> })();
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/cc335b00-56eb-46c3-a346-4d2f132ef1f1%40googlegroups.com.

Reply via email to