RiveScript gives an error for python object macros

670 views Asked by At

Is it possible to access the object macros internally in RiveScript? I'm bit confused with that. I have defined the following script:

> object small python
  return "4"
< object

+ small
- <call>small</call>

Which gives me an error when I enter small:

error: [ERR: Object Not Found]
2

There are 2 answers

2
agold On

The definition of the object seems to be ok, but you are probably running it from https://play.rivescript.com/ or https://www.rivescript.com/try, which only allow JavaScript or CoffeeScript (see the about page).

You can use rivescript-python to run the code, which you can install by:

pip install rivescript

Then put your rivescript in a file (.rive), for example, in helloworld.rive.

Then in python:

from rivescript import RiveScript
bot = RiveScript()
bot.load_directory('.') # set your directory where the .rive file(s) is/are
bot.sort_replies()

Now you can use bot.reply to get the answer for a certain input:

>>> bot.reply('localuser','small')
'4'

Edit: I have tested this code on Ubuntu 14.04 with Python 3.4.3 and Python 2.7.12 and rivescript 1.14.4.

1
mohamed nasr On

make a space after the object name just like that

- <call>small  </call>