Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I chain replies #201

Closed
CarbonMan opened this issue Jan 12, 2017 · 5 comments · Fixed by #203
Closed

How do I chain replies #201

CarbonMan opened this issue Jan 12, 2017 · 5 comments · Fixed by #203

Comments

@CarbonMan
Copy link

CarbonMan commented Jan 12, 2017

Playing with calculations, I want to be able to input
"10 times 4 divided by 2"
is that possible?

Here's what I have;

> object multiply javascript
	var operand1 = args[0].trim();
	var operand2 = args[1].trim();
	return "" + eval(operand1 + "*" + operand2);
< object
+ [what] [is] # (times|multiplied by) #

> object divide javascript
	var operand1 = args[0].trim();
	var operand2 = args[1].trim();
	return "" + eval(operand1 + "/" + operand2);
< object
+ [what] [is] # divided by #
- The result is <call>divide <star1> <star2></call>

+ (*) # divided by #
- {@ <star1> <call>divide <star2> <star3></call> }

^^^^^ That is where the problem
Any ideas?

@kirsle
Copy link
Member

kirsle commented Jan 12, 2017

Your triggers are very similar so my guess is that both forms of message are matching the same trigger.

+ [what] [is] # divided by #

This is essentially # divided by # with optional words what and is in front. Either of those words could be left out, so saying "5 divided by 3" would match the trigger.

+ (*) # divided by #

This is # divided by # with "anything" in front. The * could match strings like "what is", "is", "what", or any other text. Like "do you know 3 divided by 2" would match that trigger too.

On a side note, the (*) is probably also confusing the <star> tags. I'd expect <star1> and <star2> to both refer to the (*) in the trigger, and for <star3> and <star4> to be the numbers. You should remove the parenthesis, and make the trigger * # divided by #

To see what's going on, run RiveScript in debug mode and see which trigger matches each message.

@CarbonMan
Copy link
Author

CarbonMan commented Jan 13, 2017

So "1 + 1 times 7" matches this

+ * # (times|multiplied by) #{weight=100}
- {@ <star1> <call>multiply <star2> <star4></call> }

but the response is
I'm not sure I understand you fully.multiply {__call_arg__}1{/__call_arg__} {__call_arg__}7{/__call_arg__}</call> }
"I'm not sure I understand you fully" is the default response which is probably getting "1 +" as the input. Unfortunately it seems the <call> is translated, but never executed.
So my guess is that calls and redirections don't play well together.

Edit (kirsle): formatted your code in a fenced code block.

@CarbonMan
Copy link
Author

CarbonMan commented Jan 13, 2017

I tried this as well but the effect was essentially the same

+ * # (times|multiplied by) #{weight=100}
- <set myResult=<call>multiply <star2> <star4></call>>
^ {@ <star1> <get myResult> }

Edit (kirsle): formatted your code in a fenced code block.

@kirsle
Copy link
Member

kirsle commented Jan 19, 2017

Ahh, I see what's going on now. This is similar to the other bugs that popped up when object macros were made async (see Asynchronous Support), such as #111 and #178.

To let object macros run asynchronously, they are handled in two passes (the first one mangles them into those ugly {__call_arg__} style tags; the second actually runs it, resolves its returned promise and replaces the ugly tags with the final result). But just like for conditionals, the object macro needs to be resolved 'immediately' before the {@...} redirect around it can be followed. That isn't happening, so the redirect message contains the ugly mangled tags.

The wiki link above has more background info if you're curious. The <call> tag has always been a special creature, but it's doubly so in the JavaScript version when it wants to support asynchronous calls.

I'll be able to fix the case of "<call> tag inside {@}" (but it will support synchronous macros only, like conditions), but the <set myResult=<call>...</call>> won't work still as that's a harder problem to solve.

@kirsle
Copy link
Member

kirsle commented Jan 19, 2017

RiveScript.js v1.17.2 should fix the bug for synchronous object macros in redirects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants