Alexa customers love a good trivia game. During family game nights, players who have the answers get to show off their knowledge, while other players get to learn something new. With the launch of Echo Buttons, you have an opportunity to turn voice-first trivia games into engaging multiplayer experiences.
The new Echo Buttons trivia template shows you how to build trivia games with the Gadgets Skill API (beta). All you have to do is provide the trivia facts and plug them into the easy-to-use template. And if you’ve already submitted a voice-first game skill, you can use the trivia template as an example of how to incorporate Echo Buttons with your existing skill.
When developing any Echo Button game, you have to implement logic for discovering and associating Echo Buttons with players. This logic is referred to as “roll call.” In addition, you have to implement question-and-answer game logic. The Echo Buttons trivia template provides a solid foundation for both of these requirements.
Pick a Theme and Customize Your Trivia Content
The first step to build a trivia game using the new template is to select a theme for your game. Once identified, you will need to pull together your own list of trivia questions. With this template, it's easy to get started building your own trivia skill. Many customizations will not require code changes.
The questions used during the game are loaded by the skill from an array found in the file called questions.js, located in lambda/custom/config. Each question consists of an object with the following properties:
-
Index – The ordinal index of the question in the collection of question
-
Question – The text of the question (this is what Alexa asks players)
-
Answers – An array of multiple answers that Alexa offers contestants to choose from
- Correct_answer – The actual correct answer for the question
questions: [
{
index: 1,
question: 'What is the name for a group of lions?',
answers: ['pack', 'pride', 'den', 'frat'],
correct_answer: 'pride'
},
{
index: 2,
question: 'What type of animal is a seahorse?',
answers: ['crustacean', 'arachnid', 'fish', 'shell'],
correct_answer: 'fish'
},
When adding or updating questions and answers, you must compile a list of all values in each of the answers arrays for all questions and add each one to a custom slot in the interaction model called answers. This custom slot is mapped to two intents: AnswerOnlyIntent, which contains only the slot by itself in order to maximize the accuracy of the model; and AnswerQuestionIntent, which provides recognition of more complex utterances that users may include with their answers.
For example:
AnswerQuestionIntent is it {answers}
AnswerQuestionIntent the answer is {answers}
AnswerQuestionIntent I think it is {answers}
See the interaction model file at models/en-US.json for a complete example that you can further customize.
Enhance Game Play with Game Option Parameters
After you’ve selected your theme and created your trivia questions, you can choose to customize additional GAME_OPTIONS parameters that can be found in the settings.js file located under lambda/custom/config. This is how you tailor your game experience. For example, you may want your game to present questions in order of difficulty, you may want to give players a single chance to answer each question, or you want the game to be head-to-head vs. multiplayer. Below are a few options you can use to tailor your game experience:
- The MAX_PLAYERS parameter specifies a limit on how many players should be allowed to participate in the game. This should be a non-zero numeric value up to four. That is because the maximum number of buttons that can be connected to Alexa is four.
- The QUESTIONS_PER_GAME parameter configures the total number of questions that should be asked during each game. This number should be less then, or equal to the total number of questions that are defined in the questions.js file
- The QUESTIONS_PER_ROUND parameter configures the number of questions that should be asked per round. It specifies after how many questions Alexa should take a moment to give a score summary. If this number is larger than or equal to QUESTIONS_PER_GAME then Alexa will not give any summaries until the game is over.
- The ANSWER_SIMILARITY parameter controls how strictly answers match to the expected correct answer in order to be accepted. This should be a value between 0 and 1. The higher the value, the more exact match is required when answering the question. A value of 0.6-0.7 gives pretty good results but you should test with your own questions to determine what the right value is for your list of questions.
- The MAX_ANSWERS_PER_QUESTION parameter configures the maximum number of failed attempts allowed to answer each question. Setting this value to 0 makes it so players only get one opportunity to answer each question, If an incorrect answer is given, Alexa will move on to the next question without awarding any points for the missed question.
- The SHUFFLE_QUESTIONS parameter controls whether Alexa will ask questions in the order they are indexed in the questions.js file, or whether it will randomize the order that questions are asked
Customize the Roll Call Experience for Players
As mentioned earlier, roll call is important for your skill to assign Echo Buttons to specific players. The Echo Buttons trivia template provides options to handle roll call that do not require writing any code. While the template does the heavy lifting, you can easily customize it by providing your own user interface elements such as speech prompts or visual cues.
All the user interface elements used by the skill, including during roll call and the actual game play, are defined in a file called uiprompts.js, located in lambda/custom/dialog. Identified by a key, each element is defined as an object with properties such as outputSpeech, reprompt, displayTitle and displayText, that consist of corresponding content for Alexa to use as output speech or display text. Because each parameter is defined as an array, you can easily add variety to your skill by providing multiple sample variations for each prompt.
Other ways to customize the user experience are to change the audio and visual cues used during roll call. These can all be found as configurable properties defined in the settings.js file, located in lambda/custom/config. The Echo Buttons trivia template uses an audio clip that is played during roll call named ROLL_CALL_WAITING_AUDIO. The light animations and colors used on the buttons during the roll call process can all be customized by updating the corresponding animations found in the ANIMATIONS map in the settings.js file.
Publishing Your Own Trivia Skill
While the template simplifies building a trivia game skill, you should still consider all the best practices for building for voice as well as the additional considerations when building skills for Echo Buttons. Before you submit your skill for certification, make sure to update the skill interaction model, the UI prompts, and the skill details to reflect the name of your skill.
3 Steps to Get Started with the Gadgets Skill API (Beta)
Follow the steps below to start building today:
- Get Echo Buttons: Visit Amazon.com/EchoButtons to purchase your two-pack of Echo Buttons!
- Access the Echo Buttons Trivia Template and Gadgets Skill API (Beta) Tech Docs: Reference the trivia template, technical documentation, and the sample code to build your first Echo Button game skill.
- Build and Publish Your Game Skill: Log in to the developer portal and start building.
Source: Alexa Developer Blog