Collecting a list of inputs


#1

I’m working on a memory game where you will be asked to remember an increasing list of a certain type of inputs like digits, names, colors, etc. Right now I’m stuck at a point where my app says the list of items and when I repeat those items it ends the session.

It appears that it recognized the right intent but I have no idea why the session is ending and I have print statements inside the intent that don’t get executed which leads me to believe it isn’t actually executing it.

So I was wondering if my model is wrong/how you might create an intent that could capture a list of random inputs. My attempt is below.

Inside train.js

DigitTrainingState: {
    DigitGameIntent() {
        console.log('In DigitGameIntent');
        var digits = [0,1,2,3,4,5,6,7,8,9];

        // Start with 5 and increase by 1 incrementally
        if (this.$session.$data.digits_round == 1) {
            this.$session.$data.digits_arr = Array.from({length: 5}, () => digits[Math.floor(Math.random() * 10)]);
        } else {
            // TODO: Keep track of highest number of digits remembered.
            this.$session.$data.digits_arr.push(digits[Math.floor(Math.random() * 10)])
        }

        // TODO: Make sure digits are said correctly.
        this.followUpState('DigitTrainingState')
            .ask('<say-as interpret-as="digits">' + this.t('train.digit.game.speech', { digits: this.$session.$data.digits_arr.join("") }) + '</say-as>', this.t('train.digit.game.reprompt')); 
    },
    DigitScoreIntent() {
        // Did the user get all of them correct?
        console.log('Starting scoring intent');
        var correct_answer = this.$session.$data.digits_arr;
        var user_answer = this.$inputs.digits.value;
        console.log(user_answer);

        var score = core.calculateScore(correct_answer, user_answer);
        console.log(score);
        if (score == 100) {
            this.$session.$data.digits_round++;
            // TODO: Insert positive interjection or make a positive sound
            return this.toStateIntent('TrainState.DigitTrainingState', 'DigitGameIntent');
        } else {
            this.$session.$data.digits_times_wrong++;
            // TODO: Keep track of how many times user has gotten it wrong consecutively.
            // If wrong consecutively twice, offer hint or different message.
            return this.toIntent('RepeatIntent');
        }
    }
},

Inside en-US.json

{
	"name": "DigitScoreIntent",
	"phrases": [
		"{digits}"
	],
	"inputs": [
		{
			"name": "digits",
			"type": {
				"alexa": "AMAZON.NUMBER"
			}
		}
	]
}

Request JSON

{

* "version": "1.0",
* -

"session": {
  * "new": false,
  * "sessionId": "amzn1.echo-api.session.0000000-0000-0000-0000-00000000000",
  * -

"application": {
    * "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe"},
  * -

"attributes": {
    * "name": "Jon",
    * "_JOVO_STATE_": "DigitTrainingState",
    * "digits_round": 1,
    * -

"digits_arr": [
      * 6,
      * 4,
      * 0,
      * 1,
      * 7]},
  * -

"user": {
    * "userId": "jovo-debugger-user"}},
* -

"context": {
  * -

"System": {
    * -

"application": {
      * "applicationId": "amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe"},
    * -

"user": {
      * "userId": "jovo-debugger-user"},
    * -

"device": {
      * "deviceId": "amzn1.ask.device.XXXXXA6LX6BOBJF6XNWQM2ZO4NVVGZRFFEL6PMXKWLOHI36IY3B4XCSZKZPR42RAWCBSQEDNGS746OCC2PKR5KDIVAUY6F2DX5GV2SQAXPD7GMKQRWLG4LFKXFPVLVTXHFGLCQKHB7ZNBKLHQU4SJG6NNGA",
      * -

"supportedInterfaces": {
        * "AudioPlayer": { },
        * -

"Display": {
          * "templateVersion": "1.0",
          * "markupVersion": "1.0"},
        * "VideoApp": { },
        * -

"Alexa.Presentation.APL": {
          * -

"runtime": {
            * "maxVersion": "1.0"}}}}},
  * -

"AudioPlayer": {
    * "offsetInMilliseconds": 0,
    * "playerActivity": "IDLE"}},
* -

"request": {
  * "type": "IntentRequest",
  * "requestId": "amzn1.echo-api.request.0000000-0000-0000-0000-00000000000",
  * "timestamp": "2019-05-14T01:43:20.556Z",
  * "dialogState": "COMPLETED",
  * "locale": "en-US",
  * -

"intent": {
    * "name": "DigitScoreIntent",
    * "confirmationStatus": "NONE",
    * -

"slots": {
      * -

"digits": {
        * "name": "digits",
        * "value": "six four zero one seven"}}}}

}

Response JSON

{

* "version": "1.0",
* -

"response": {
  * "shouldEndSession": true},
* "sessionAttributes": { }

}

#2

Hey @Porterhaus!

Your code looks fine to me.

Could you add this to your handler:

 ON_REQUEST() {
      console.log(this.getRoute());
 },

#3

It appears to be going to the right place. Weird.

{"path":"DigitTrainingState.DigitScoreIntent","state":"DigitTrainingState","intent":"DigitScoreIntent","type":"INTENT"}
{
  "version": "1.0",
  "response": {
    "shouldEndSession": true
  },
  "sessionAttributes": {}
}

#4

That’s really weird. Could you try to put DigitScoreIntent outside of the state.


#5

I realized I had to use

this.followUpState('TrainState.DigitTrainingState')

instead of

this.followUpState('DigitTrainingState')

in the DigitGameIntent and that fixed it!


closed #6