aichaos / rivescript-js

A RiveScript interpreter for JavaScript. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
377 stars 144 forks source link

ERR: No default topic 'random' was found! #259

Closed s-mv closed 6 years ago

s-mv commented 6 years ago

I am not using any external library and pure JavaScript, but it says that the topic random was not found...

kirsle commented 6 years ago

That error usually means it didn't load any replies. Run it in debug mode (new RiveScript({debug: true})) and see if it's reading the .rive files correctly.

s-mv commented 6 years ago

Thanks, I'll check it out!

On Wed, Apr 4, 2018, 22:01 Noah Petherbridge notifications@github.com wrote:

That error usually means it didn't load any replies. Run it in debug mode (new RiveScript({debug: true})) and see if it's reading the .rive files correctly.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aichaos/rivescript-js/issues/259#issuecomment-378663399, or mute the thread https://github.com/notifications/unsubscribe-auth/AfDeEmbfJFJgvJeNgyxk78ivf7Q86nVHks5tlPV7gaJpZM4TGbwP .

s-mv commented 6 years ago

Hi! The error continues... Let's see: my index.html -

<html>
<head>
<script src="libs/rivescript.min.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<noscript>Sorry, JavaScript is needed</noscript>
<title></title>
</head>
<body>
    <header></header>
    <div id="chatlogs" style="height:70vh;">
    </div>
    <input placeholder="Type some text" >
    <button>Send</button>
</body>
</html>

main.js -

window.onload = function(){
    var bot = new RiveScript({debug: true});
    bot.loadFile("brain.rive", brainReady, brainError);
    function brainReady() {
        console.log('Chatbot ready!');
        bot.sortReplies();
        var reply = bot.reply('local-user', 'set ');
    }
    function brainError() {
        console.log('Chatbot error!')
    }

    var button = document.querySelector('button');
    var input = document.querySelector('input');
    var output = document.querySelector('#chatlogs');

    button.addEventListener("click",chat);

    function chat() {
    var reply = bot.reply("local-user", input.value);
    output.textContent = reply;
    }
}
s-mv commented 6 years ago

The markdown doesn't work nicely on the phone!

s-mv commented 6 years ago

I tried other browsers, but all show the error

s-mv commented 6 years ago

It isn't working on itch.io too...

kirsle commented 6 years ago

Use the browser console's Network tab and see if the ajax request to load brain.rive went through okay. Also the browser console should log a lot of stuff as it parses brain.rive -- listing every line it reads and what it's doing with it. If you don't see the debug logging, it may mean it isn't able to get the file (wrong file path, permission problem, etc.)

Also if you were testing it by double-clicking the index.html to open the web page locally, that won't work, as browsers block ajax requests from local pages trying to access local files for security purposes.