[Course] Project 2: Adventure Game


#1

Welcome to our second project-based course about voice app development. After completing Project 1: Hello World, you now have a basic understanding of how voice apps work and how to set Alexa and Google Assistant up for simple responses.


This is a companion discussion topic for the original entry at https://www.jovo.tech/courses/project-2-adventure-game

#2

Hello!

I have a question about the functions located outside the app.setHandler.

For example, imagine that you have the following code inside app.setHandler:

if (this.$inputs.color.value === 'blue') {
        speech = 'You chose to go through the blue door.'
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.'
            \+ ' Do you want to follow the sound?';
        reprompt = 'Please say yes or no.';
        this.ask(speech, reprompt);
}

If I add this code to a function such that:

if (this.$inputs.color.value === 'blue') {
    readFunction();
}

And out of the app.setHandler I add these function:

function readFunction() {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     this.ask(speech, reprompt);
}

I have an error in this.ask:

Message:
Cannot read property ‘ask’ of undefined

Can someone help me? Thank you in advance!


#3

Can someone please help me? :pensive:


#4

In your handler, pass the Jovo context object like this: readFunction(this);

And then accept the jovo object in your helper function like this:

function readFunction(jovo) {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     jovo.ask(speech, reprompt);
}

Alternative: You can also use readFunction.call(this); and don’t need to accept the jovo object then, because the context will be passed to the helper method:

function readFunction() {
     speech = 'You chose to go through the blue door.
            \+ ' There is a dark, long floor. Suddenly, you hear a sound from a room at the end of it.
            \+ ' Do you want to follow the sound?';
     reprompt = 'Please say yes or no.';
     this.ask(speech, reprompt);
}

#5

Thank you so much Jan!!

It works correctly!

Thank you very much for your reply.

Greetings! :grin:


#6

How to ask user to fill intent slot?

For Example the user has initated the intent “book Hotel”, but has not given an required Intent Slot ‘city’.

With an Alexa skill i would delegate it to dialog system and alexa would ask the user by the predefined question. But how do i do it with jovo that it works for alexa and googleAction?


#8

hi
there have github code for this tutorial ?


#9

Not yet, but great idea!