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

use condition with star (if exist, star reply ; otherwise default reply)

Open elpimous opened this issue 6 years ago • 4 comments

Hi Noah, hi all, need to find a way to success : I try to reduce routine, and find better reply than "catch all trigger" here is what I'd like to do :

+ what is a *
* @ <star>
- I don't know what it is

+ ball
- a rounded object

If the star correspond to an existing trigger, it speaks it reply either, it reply specific default reply

Any help ?

elpimous avatar Jun 18 '18 21:06 elpimous

I did another test :

+ what is a *
@ <star>

+ what is a *
- I don't know what it is

+ ball
- a rounded object

Doesn't work !

elpimous avatar Jun 18 '18 21:06 elpimous

found an idea, but perhaps there is simpler !! I just created a specific catch trigger !

+ what is a *
@ object <star>

+ object *
- I don't know what it is

+ object ball
- a rounded object

elpimous avatar Jun 18 '18 21:06 elpimous

Something like this might work: https://play.rivescript.com/s/ss8WgUpO4p

! version = 2.0

// Wildcard replies normally under normal conditions but
// will reply `no-match` when the uservar `testing=true`
+ *
* <get testing> == true => no-match
- I don't know how to reply to that.
- Try asking a different way.

// set testing=true to test the wildcard for a trigger match.
+ what is a *
* <set testing=true><@> != no-match => <@><set testing=false>
- I don't know what it is.<set testing=false>

+ ball
- A rounded object.

+ box
- A square object.

The condition sets the uservar testing=true before redirecting to <star> (<@>)... the catch-all trigger will test if we're testing and say no-match if no match, which is easy for the condition to match on.

This lets the wildcard trigger continue working as normal for when the user says something completely wrong.

Ideally I'd want to have <set testing=false> inside the wildcard condition but it seemed like it didn't process the <set> tag in there. Probably a bug (in the JS version) and Python may not be affected by it, but you may wanna do some experimenting.

Example:

// clean up the `testing` variable after testing it,
// but for the JS edition of RiveScript this didn't
// take hold until the wildcard trigger itself was
// matched directly in a future reply.
+ *
* <get testing> == true => no-match<set testing=false>
- I don't know how to reply to that.
- Try asking a different way.

kirsle avatar Jun 18 '18 21:06 kirsle

Wow ! What a complete answer !! As usual, thanks Noah, for your soft and your support !

elpimous avatar Jun 19 '18 18:06 elpimous