The JavaScript object macro runs in the same system as the RiveScript bot itself (if the bot is in the Node server, then the object macro runs there; if run in a browser, it runs in the browser).
The `scope` parameter can be used to make the object macro run the perspective of a different scope. How you’d use it is to pass a scope in to the reply() function, like,
var reply = bot.reply(username, message, this);
The `this` would then be passed all the way through to the JS object macro, and the macro would then be running from the scope of your actual code (from where you called `bot.reply()`), so if your JS code is structured in an object-oriented way it would allow the JS object macro to access your other private variables/methods which it otherwise wouldn’t be able to if it was executing from the global/top-level scope (which is the default, iirc).
Anyway, `bot._users[username]` is indeed where variables get stored for the users (you can test it here: http://www.rivescript.com/try after you start a conversation you can print `bot._users[“local-user”]` in the JS console).
But don’t use `_users` that way, as it’s a “private” object (hence beginning with an underscore); there’s a function `getUservar()` which provides a public API interface to getting a user variable.
So, full example,
+ i am (happy|sad)
- <set mood=<star>>I see.
+ what mood am i in
- Your current mood is: <call>coolfunc</call>
> object coolfunc javascript
var mood = rs.getUservar(rs.currentUser(), "mood");
return mood !== "undefined" ? mood : "unknown";
< object
You can copy/paste it in http://www.rivescript.com/try to test.
User: What mood am I in?
Bot: Your current mood is: unknown
User: I am happy
Bot: I see.
User: What mood am I in?
Bot: Your current mood is: happy
User: I am sad
Bot: I see.
User: What mood am I in?
Bot: Your current mood is: sad