Not sure what you mean but here’s a couple ideas:
1) You can use setSubroutine() to set a JS function from your JS code
Example
var rs = new RiveScript();
var extraFunction = function() {
return "A function that you can call from the JS file scope";
};
rs.setSubroutine("myJsFunction", function(rs, args) {
console.log("hello world!");
// you can access any variables in the scope of this function
var test = extraFunction();
return "return value";
});
The body of the function in `setSubroutine()` would be the same as in the `>object` in RiveScript, but your function would have access to any variables/functions in its parent scopes too (which you can’t get from the `>object` version)
2) Use the `scope` parameter in rs.reply()
Another way to handle scope of external variables/functions with the `>object` syntax, is to pass the scope variable `this` into the reply() function, like
var reply = rs.reply(username, message, this);
And then from inside the JS object macro, the `this` variable would be the very same `this` as what got passed in (and it has access to other local functions/attributes).
There’s a full example of the scope parameter here: https://github.com/aichaos/rivescript-js/tree/master/eg/scope