possible tj.listen() issue
Closed this issue · 1 comments
This might be an generic issue with using node.js or a problem with the tj.listen(). Here's my scenario. I have a conversation feedback loop: listen(), converse(), speak(), and repeat.
This is all handled through a callback in the listen command.
However, I need to briefly pull out of this feedback loop to play a mini-game with tjbot where I orchestrate all of the commands (listen, speak, wave, and shine) and then return to this feedback loop when completed. What I am finding is that when I stop listening and start listening from another function, the original feedback loop starts processing the utterance instead of the function I had just called.
e.g.)
//main feedback loop
tj.listen(function(msg){
tj.pauseListening();
tj.converse(function(resp){
if (rest == "play game"){
playGameA();
}
tj.resumeListening();
});
});
function playGameA(){
tj.stopListening();
tj.speak("What is your favorite color?");
tj.listen(function(msg){ //this command is being picked up by the main feedback loop above
if (msg == "red"){
doSomething();
}
});
}
I actually solved this issue by introducing a self-created state-machine and running the mini-game through it. It returns to the main callback to process the user's speech when necessary but then passes the result onward to the state-machine for continue processing until the state machine is completed. Then any more utterances will be processed by tj.converse().