rivescript-js
rivescript-js copied to clipboard
run multi - conditions within one line?
It would be a great feature to have down the road to run more than one conditions in one line
Currently, have to do several triggers
+ varcheck
* <get money> == 0 => {@varcheck2}
- {@mainmenu}
+ varcheck2
* <get mood> == sad =>{@varcheck3}
- {@mainmenu}
+ varcheck3
* <get time> == 1200 =>{@needhelp}
- {@mainmenu}
Would be cool to add "and" "or" to the conditional
+ varcheckboth
* <get money> == 0 && <get mood> == sad && <get time> ==1200 => {@needhelp}
- {@mainmenu}
+ varcheckor
* <get money> == 0 || <get mood> == sad => {@itsok}
- {@mainmenu}
+1 😁
This is a good idea. For implementation notes (if somebody else wants to take this on before I get around to it), if you split a string using a regular expression with a capture group, the capture group itself gets returned in the array output.
Example:
> a = "<get money> == 0 && <get mood> == sad || <get time> == 1200"
> a.split(/(&&|\|\|)/)
[ '<get money> == 0 ',
'&&',
' <get mood> == sad ',
'||',
' <get time> == 1200' ]
I don't think I'll care to implement grouping of conditions with parenthesis (e.g. (a || b) && c), which would add a ton of complexity; so this is my thought on how the algorithm could be implemented:
- Split at
&&and|| - Step through the array; for each item that does a conditional check, do what the code currently does.
- If the condition is false, but the next token is an
||, keep going and check the next condition - If the condition is false, and the next token is an
&&, the overall condition fails and stop checking the rest of the line.