脚本返回对象Promise而不是返回回调

时间:2018-07-13 06:43:36

标签: javascript rivescript

function setup() {<br>
  noCanvas();

  let bot = new RiveScript();<br>
      //bot.loadFile("brain.rs", brainReady, brainError);<br>
    bot.loadFile("brain.rive").then(brainReady).catch(brainError);<br>

  function brainReady() {<br>
    console.log('Chatbot ready!');<br>
    bot.sortReplies();<br>
    let num = floor(random(20)) + 1;<br>
    console.log(num);<br>
    let reply = bot.reply('localhost', 'set ' + num);<br>
  }

  function brainError() {<br>
    console.log('Chatbot error!');<br>
  }<br>


  let button = select('#submit');<br>
  let myInput = select('#myInput');<br>
  let output = select('#output');<br>

  button.mousePressed(chat);<br>

  function chat() {<br>
    let input = myInput.value();<br>
    let reply = bot.reply("localhost", input);<br>
    output.html(reply);<br>
  }<br>
}<br>

0 个答案:

没有答案