rivescript-js icon indicating copy to clipboard operation
rivescript-js copied to clipboard

Dynamic Arguments to <call> Tag

Open ssc2015 opened this issue 7 years ago • 3 comments

One of the comments in an earlier issue (How do I chain replies) mentioned that setting a variable by calling a macro, like below, is a harder problem to solve.

<set myResult=<call>...</call>>

Is there any update on this? We need a way to pass a dynamic date parameter to the <call> tag.

ssc2015 avatar May 01 '17 14:05 ssc2015

You can set user variables from inside the macro if that works.

rs.setUservar(rs.currentUser(), "myResult", "x");

kirsle avatar May 01 '17 17:05 kirsle

@kirsle, I have tried the following but the args in the sub are empty.

Is this because "get" is evaluated before calls are processed?

! version = 2.0

+ test
- <call>date</call> <call>sub <get date></call>

> object date javascript
rs.setUservar(rs.currentUser(), "date", new Date().toString());
< object

> object sub javascript
console.log(args);
return "Args: " + args.join(',');
< object

ssc2015 avatar May 02 '17 14:05 ssc2015

Yeah the <call> tag is always the very last one processed. You could use rs.getUservar() inside the macro to get the variable too.

kirsle avatar May 02 '17 15:05 kirsle