Remember to Version Your Lambda Function

Here’s a newbie mistake you can avoid. My Guess the Total skill for Alexa uses a Lambda function. I got everything set up, and the skill went live yesterday. I followed that up with a bit of a marketing splash. (See yesterday’s post.)

Now I want to add a new feature. So what happens when I change my Lambda function? I will break the game for everyone who is busy trying it out.

The right thing to do is to create a version of my Lambda function and point the Alexa skill to the specific, unchanging version. Even better, the skill can refer to an alias that points to the version. Then the skill can keep pointing to the alias even if the underlying version changes.

Indirection leads to happiness.

Now I might need to bit the bullet, create a version, and point my skill to that version. That action would trigger another review of my skill, which means it will go offline for about a day.

Normally that would be tolerable, except for the big marketing push. People will probably be kicking the tires of my skill well into next week.

So I might make a new Lambda function and set it up with versioning from the start. I can point the development instance of my skill to the new Lambda. The next release won’t have this issue.

Or I could do something else for a week and wait for feedback. Choices, choices.

How I Made My First Voice-activated Game

guess-the-total-banner

Last week, I wrote about my struggles with Alexa, Amazon’s virtual voice assistant. Sometimes you just have to stare a problem down to make it go away. It worked, and a few working days later, my new Alexa skill is ready to go.

Sometimes it helps to see the whole picture. Think about making a nice dinner. You may have recipe books full of foods you would like to eat. Easy enough if you are adept at cooking.

Coming up with a complete dinner involves another level of orchestration. You need to select a few specific recipes and come up with a menu that has a nice mix of foods. Some protein, a little starch, a nice mix of vegetables, a tasty dessert. Then you have to prepare the food in the right order and with just the right timing to come out when it’s time to eat. Not too soon, and not in dribs and drabs that leave your guests wondering if they will go home hungry.

So, I am going to share how I came up with my particular meal, so to speak. This is a semi-technical rundown of everything I bumped into and had to figure out to get my skill written and published.

Want to know how I did it? Keep reading for lots of gory details.

Guess the Total

My skill teaches Alexa how to play Guess the Total, a game that I invented with my daughter during her daily bath time when she was still little but old enough to count. I have explained the game previously, but allow me to recap.

The game generally requires two or more players. In the skill I programmed, it’s just two players: you vs. Alexa. Each player thinks of a secret number within a range, say from 0 to 10. Then they take turns guessing the total of the secret numbers. Whoever is closest wins.

Simple.

I used to call this game Guess the Sum. When I got around to trying it on my Echo Dot, I found that Alexa misinterpreted the invocation command half of the time. Every other round, she kicked off a lively game of Guess the Song. Um, Alexa, stop.

Through this turn of events, I learned an bonus marketing lesson. When you quit Guess the Song, the skill tells you about other skills by the same publisher. Good idea, despite my mild annoyance after the fifth or sixth time. Alexa, really, stop.

So I renamed my game Guess the Total. That sounds better anyway, and with Alexa it’s all about how things sound.

So now you invoke my skill by saying, “Alexa, open Guess the Total.” She responds with instructions for how to start the game or get directions. In skills parlance, these are called intentions, and they are built into my skill model. When you say “play the game,” Alexa guides you through it.

As the skill logic stands, Alexa always lets you go first. She asks for a couple of numbers, and you have to give answers that make sense. When your turn is over, Alexa takes her turn and reveals the winner. She shares the number she picked and her guess. Then she reveals the sum of the secret numbers and explains who was closer. If you win or tie, she tells you how many points you get. She awards an additional point for an exact guess.

Then she promptly forgets everything, and asks if you want to play again. Pretty much the way I played with my daughter when I invented the game.

Now you might think that telling Alexa your “secret” number is a bad idea. After all, she’s your opponent, and it would be sooo easy for her to cheat. Except that I programmed the skill to play fairly, so you don’t have to worry about that.

That’s it. Simple enough. The basic mechanic of the game is working. You can get from start to winner in a matter of seconds. Players are nudged back on track when they say something weird. For instance, when asked for a secret number, the player might say “banana.” Alexa will recognize that banana is not a number and ask the player again.

While Guess the Total has lots of room for improvement. at this point I think it’s good enough to share. By pushing out the minimum amount of scope that is playable, I got to learn about the publishing process, and I can start getting feedback from real players.

Plus, I already have my next release planned. So I can push improvements a little at a time to the delight of players around the world. Oh yes, I will take the world incrementally by slow-moving storm.

I know. Dry humor is so hard to read on a web page.

Moving right along…

Learning New Technology

You may not realize that the phrase “new technology” has layers. The technology might be new to you, like when a caveman is found frozen in an icecap and is revived to discover the magic of electricity and combustion engines. Or new technology might literally be brand new.

Alexa is new relative to gas-powered cars but mature enough to have whatever gaps and kinks there used to be worked out. You might still think of it as leading edge technology without being on the bleeding edge.

Lots of technology I use when writing software is somewhere along the newness spectrum. Here’s my general approach for tackling new software technology.

  1. Read an inspirational overview of the awesome reasons to use the technology. This often includes hints of riches, the good life, or saving the world. Usually I have something in mind that I am trying to accomplish, and I’ll imagine how this technology will help with my mission.
  2. Work through a “Hello World” tutorial. This is a simple way to get the basic environment set up and to prove that at least the simple stuff works. Also, if you cannot get “Hello World” to work, there’s not much point in continuing. Usually, it’s fine and introduces core concepts of the tech.
  3. Try to adapt “Hello World” to a non-trivial purpose. Basic tutorials tend to be too simple for vetting the technology. You need to throw a few non-trivial problems against it to get a sense of whether the tech will help and what the gaps might be. I like to use the solution I imagined in step 1 as a proving ground. By going deep on a real problem, I tend to discover documentation, example code, and discussion boards.
  4. Dig into a few thorny problems. Beyond that, a variety of factors influence where things go. Can I get a happy path to work where users pick all of the right answers? Do I need to restructure the “Hello World” project to handle added complexity? Have others figured out “best practices,” or at least a few tricks that help?
  5. Decide to fish or cut bait. At some point, the tech is either good enough or not worth the struggle.

Luckily, Alexa is works mostly as expected so far. In some cases, I had to adjust my mental model or approach. That’s called learning, which is part of the fun.

The Elements of a Skill

Skills are relatively straight-forward. They start with an invocation name, the phrase you tell Alexa to kick things off. Each skill is tuned to fulfill a set of intents, things that people want Alexa to do. The default skill model includes some common pre-built intents for things like getting help and quitting.

 

AlexaConsole-SkillInvocation

A view from the Alexa Developer Console

 

For Guess the Total, I have two intents: PlayGameIntent and GetDirections.

Intents are triggered via utterances, things people might say when they want something. In the skill model, you supply sample utterances for each intent. These are supposed to be conversational and should include various ways to say the same thing.

For instance, to get directions, you can say “Give me the directions,” or “Tell me how to play,” or “What are the rules?”

 

AlexaConsole-SkillIntent-Utterances

Utterances that imply the “Play Game” intent

 

An intent performs an action or provides some information. The GetDirections intent gets Alexa to explain how to play Guess the Total. Kind of a one-off intent, a simple request-response interaction.

The PlayGameIntent is more involved. By providing Alexa with a dialog model, she is able to manage a conversation with the player and collect the information needed to fulfill the intent. In the case of Guess the Total, Alexa needs to gather a secret number and a guess from the player. This information is placed into slots to be used in the logic that handles the intent.

 

AlexaConsole-SkillIntent-Slots

Slot definitions for the “Play Game” intent

 

Let’s say that Alexa asks the player for a secret number, and the player says “six.” The playerSecretNumber slot gets populated with a 6. Then Alexa asks for the player’s guess, and she says “twelve.” The playerGuess slot holds the value 12. Everything is peachy, and Alexa takes it from there.

Now let’s say that the player is being tricky and says “pineapple” for her guess. The playerGuess slot gets populated with ‘?’ because Alexa is expecting an integer. That’s where my code takes over and directs Alexa to reprompt the player for a better slot value. The same kind of re-prompt kicks in if the player says a number that is out of bound, such as 42.

As far as I know, that touches on the main the elements of an Alexa skill. It’s not that complicated.

If you are technically inclined, you might want to look at my code on GitHub. I could do a walk-through of my code in a future post. Let me know if you’re interested. For now, let’s not scare away everyone who doesn’t write code for a living.

Tricks I Learned

If you are thinking of creating an Alexa skill of you own, here are my pointers on pulling together a three-course meal.

Setting Up

I learned two general approaches to creating a new skill.

One is to use the Alexa Console to create the skill. Then use the AWS console to create a Lambda. Then hook the two together with a few well-placed clicks and a little cut-and-paste action on the skill ID and Lambda ARN. You might call this the coder-less approach. More clicking on things and less typing.

The coder-less approach allows for some variation, particularly with how the Lambda function is created. You can start from scratch, use a blueprint, or draw from the serverless application repository.

I will admit to not quite getting the difference between blueprints and the serverless repository. I attempted to use pre-built examples of Alexa skills that seemed close to what I was trying to do with the game. None was close enough, and the naming seemed to linger. I ended up with new roles in IAM called “whatever-the-heck-that-sample-skill-was-called” backing my “guess-the-total” Lambda function. Not entirely satisfying.

I also tried using the microservice-http-endpoint app pattern. That hooked up a downstream DynamoDB instance, which will be useful at some point, but not just yet.

I also tried starting from scratch. That’s a journey you don’t want to start lightly, requiring the most knowledge of AWS technologies and how to glue them together. Probably a good idea once you have things under control on the skill and need to expand beyond your custom logic.

At some point, I tried creating a role that would be shared across all of my Lambda functions. Big plans for the days when I’ll have more than one. Well, that didn’t work. Somehow I messed up the access to CloudWatch, so the Lambda logs were not being captured.

I gotta have my logs. How else will I see what going on and more importantly what’s going wrong? So I threw away that attempt.

In all of these cases, the Lambda function started life as a single file, which is too simplistic for my use case. I prefer the project structure that the Ask CLI provides, with a zip-able set of files to upload to Lambda and an automated deployment script that I didn’t have to write.

Another pesky problem I kept bumping into has to do with regions. Presumably Alexa skills can work from a few different regions. I prefer using Oregon since it is closest to me. But the CLI tools kept insisting on sending my Lambda code to Virginia. The problem could be a lack of understand on my part of how to nudge the CLI to use Oregon. I couldn’t find any region overrides in the documentation.

I prefer automated deployment scripts that do what I want. *hrmph*

The solution for now was to let go of my desire for control over the region. Laziness wins the day.

Based on my experience with the Alexa and AWS consoles, I think the better approach is to create skills from the command line. In my case, something like:

ask new --skill-name guess-the-total

worked just fine. I was able to open the new project in VS Code, make a few adjustments, and issue the command

ask deploy

to push everything to the cloud. The CLI takes care of creating the skill, building the skill model, setting up Lambda, and pushing out that code.

The Lambda function gets set up in Virginia? No problem. At least it works. If you think you want more control than that, I say let it go. After all, we are just getting started here. Better to go with the flow and deliver something now than to be stubborn and stay stuck. Right? Right.

Alexa, show me the way.

Development

Given my setup, I make most of my changes in two places: the Alexa Console (found at developer.amazon.com), and my local IDE. I use VS Code, which is free and works well with JavaScript, JSON, Git, and everything else I need for programming.

The Alexa Console is for managing the skill. It offers a helpful editor to modify, save, and build your skill model. The editor organizes the JSON-based model the way Alexa likes it, and the build process alerts you to any errors it finds where you can easily fix them and re-build. Once the build succeeds, it’s a simple step to open the JSON Editor and copy the code into my local IDE. That keeps my local environment in sync with what’s out in the cloud.

 

AlexaConsole-SkillDetails

Working in Alexa Developer Console

 

There are command line tools for keeping things in sync. A clone command brings down the whole project, but that’s a bit heavy handed when I just need to latest model.

The CLI has a rich set of sub-commands, too. No doubt these building blocks are composed into macro commands. With a bit of work, I can see how I might program something more targeted to automate this “copy-and-paste” process. However, at the moment I am more focused on getting a skill published ASAP.

Ironically, I have no time for “time-savers.”

Let’s shift our attention to the local environment. As lovely as Lambda’s code console is, I prefer to write JavaScript using a full-fledged IDE, such as VS Code or IntelliJ IDEA. My skill handlers are written in JavaScript, and they rely on other JavaScript modules. It’s nice to let NPM manage modules for me, and VS Code makes me productive in so many other ways. Two thumbs up for Microsoft.

(Did I just write that? Yes, I did.)

Once I have something worth testing, I use the Ask CLI deploy command to push lambda changes into the cloud.

ask deploy --target lambda

A crowning virtue of keeping all of the latest code and configuration in my local environment is that it allows me to use source control to preserve my work. Git is a fabulous tool. As soon as I have created my skill project using the Ask CLI, I can create a local Git repository with git init. Voilà, instance source control.

Then it’s a simple matter of pushing that repo to GitHub so that I can pull it into any other machine I happen to use for development. I have two computers for development, a desktop machine in the home office and this laptop that I take with me, since I am on the go quite a bit.

Your situation may be different. If you spend a lot of time writing code and jumping between machines, try this out. Just remember to commit your changes frequently and keep them synced with your GitHub repo.

Testing

The Alexa Console has a few other tabs: Test, Distribution, Certification, Analytics.

My adventure with the Console Test window was hit-or-miss. More often than not, I would try to invoke my skill, and the request would never come back. The browser console shows lots of errors. I think Chrome sees the test requests as some kind of hacker attack and blocks them. Unfortunate and a tad frustrating.

Testing from the Lambda console works better. Assuming you can trust Alexa to trigger your function, focus your tests on the custom logic you have supplied. That’s certainly a more direct approach, although there is some presumption that it’s easy to know what will be in the payload that Alexa sends to Lambda.

You can test using the Ask CLI, which supports a simulate command. That seems to work and does not have the problems I saw in the browser-based tests. I haven’t yet figured out how to test a series of utterances to truly simulate the player experience.

Instead, I jumped to what might be the best testing approach. I loaded my skill onto my Echo Dot, and tested with my voice. After all, that employs the same interaction mode that regular players will use. So I got to have a true experience, not a simulation.

If you recall, that’s how I learned that I needed to rename my skill. Good to know.

For my test plan, I listed all of the possible outcomes. Here they are:

  • I ask for directions.
  • I win.
  • I win with an exact guess.
  • Alexa wins.
  • Alexa wins with an exact guess.
  • I say “play again” when the round is over.
  • I say “quit” when the round is over.
  • I say “banana” for my secret number.
  • I say “kitchen sink” for my guess.
  • I ignore Alexa when she asks for input, which triggers the re-prompt speech.

Then I played the game until I got them all to happen. By exercising those cases, I discovered a handful of problems in my code. Once they all worked, my skill was done.

And then I had my daughter try it. She humored me by playing a couple of rounds before going back to Minecraft. Hey, I wasn’t expecting any miracles. I think she enjoyed it, and more importantly, I enjoyed watching her play.

Alexa, tell me it’s all about me.

Releasing

Today my skill was approved. That means I made it through the release process. Not without a hiccup or two.

Releasing involves filling out a multi-page form where you provide marketing information: what the skill is for, any requirements for using it, the category of skill, and so on.

Amazon also wants to know your intentions where there might be legal or financial implications. Are you selling the skill? Are you marketing to children? Does your skill expose any governmental secrets?

This time I got through without raising any flags. That was my second try.

The first time around, my skill was rejected. Apparently, Alexa should never leave the user hanging. If she is going to wait for a response, the last thing she says has to prompt the user with options. Otherwise, she should end the session.

Some Alexa skills are one-shot skills. “Alexa, what is the weather?” is a one-shot—she tells you the weather and quits.

For Guess the Total, I want Alexa to keep going until the player says “quit.” The first time I went for approval, there was no explicit way out of the game, and it wasn’t clear that you could play again. So I fixed that and resubmitted.

It was nice to wake up and see this message.

Dear Dave,

Thank you for the recent submission of your skill, ‘Guess the Total’.

Congratulations! Your skill has passed our certification process and will be published to skill store shortly.

Quirks and Quacks

Most technology has quirks about. Little oddities that may get sorted out at some point. Or not. I found a few in the Alexa machinery, most of which I have already discussed. How about a few more?

Alexa is not good at hearing negative numbers. While testing my out-of-bounds validation, I tried to say numbers like “negative two” and “minus six.” Alexa would helpfully ignore the “non-numeric” part and fill the slot with 2 or 6. Nice try, Alexa.

I never tried saying a decimal. I bet that would mess things up in my game logic. Not sure how well Alexa hears decimals.

It’s not obvious that in order to keep Alexa awake you have to include a “re-prompt” with the response. Otherwise, she says her thing and ends the session. As I explained, I want Alexa to continue playing Guess the Total until the player tells Alexa to quit. So I had to include re-prompts with all of my intents except the intent to exit.

On a related note, I originally thought I could ask the player something like “do you want to play?” But the reply “yes” or “no” does not imply a specific intent. Maybe there is a way for Alexa to remember the context of the last question. The easiest thing for now was to direct players to be explicit about their intent. When someone says “play the game” or “play again” or “quit,” the intent is pretty obvious.

With time and practice, I might get better at making things conversational.

I am sure there are other quirks. Then again, once you get used to them, they become normal.

Feature Backlog

Guess the Total, as it exists today is what I consider to be a minimum viable product, or MVP. That means it does some portion of what I intend it to do well enough. Just enough to get attention, to attract players and gather feedback, and to provide a base to build on.

For my next trick, here is a prioritized list of features I am considering. I may release one at a time or batch a few together.

  1. Allow Alexa to go first. The player who goes first ought to alternate every round. The coding is different when Alexa gets to make the first guess.
  2. Up Alexa’s game. I programmed Alexa with a random strategy for choosing a number and guessing. It would be more fun if she could choose from a variety of strategies, even mixing them as more rounds are played to try and catch her opponent off guard.
  3. Keep score for a multi-round session. This would lend itself to tournament mode, where you play until you reach an overall score that definitely proves you are a champion of the world, at Guess the Total.
  4. Create a leader board. This is a big one that would mean registering users, keep stats across sessions (using a database), and having a web page to see your score and rank among the top players.

And with that juicy list of features, I may have just blocked out all of my spare time for the next six months.

I think I’ll take it one step at a time.

Wrapping Up

Guess the Total is live in the Skill Store. If you have an Echo device or the Alexa app, you can find it by searching…wait for it…Guess the Total. Yup. There it is.

Go ahead and try it. I guarantee you’ll have a moment of engaging fun while you figure out how to play and go a few rounds against the lovely and talented Alexa. She really is a charming companion.

Also, you can find news about the latest updates on this page. I already announced the release to Happy Spirit Games newsletter subscribers. Do you like be an insider? Click that link, and subscribe today.


If you enjoyed this post, let me know, and please tell others about it.

Be brave. Add a comment or ask a question. I promise not to delegate my response to Alexa.

 

Getting Schooled by Skills

Sometimes the biggest blockers are mental. It’s difficult to catch your own biases. Witness my adventure to learn how to write Alexa skills.

I have been stymied following the prescribed approaches to creating an Alexa skill. Let’s focus on the ask-cli tool, since this has the most promise of supporting an active development cycle. If I read the direction literally, I must:

  1. Install ask-cli globally.
  2. Run ask init and use the default profiles (at least while I’m still getting the hang of things).
  3. Run ask new with the skill name, since I that gets baked into the project structure. For my latest attempt, I used ask new --skill-name PizzaMaker. Yum.
  4. Run ask deploy to automagically deploy the new project to the cloud. This uses (I presume) CloudFormation or the Ask API (not exactly sure) to push the skill model, set up a Lambda with the zipped function code, and connect the two together.

With some experimentation, I was able to use the simulator to test the deployed skill. What finally worked?

ask simulate -t "alexa, open greeter" -l "en-US"

The response is a detailed JSON payload that includes the text that Alexa is to read out. So far so good.

Next I want to test the development life cycle. That means I need to change various bits of code, push them to the cloud, and see if the changes take.

  1. I change category in skill.json to GAMES.
  2. I change invocationName in the US English version of the interaction model to pizza maker.
  3. I change the response text in LaunchRequestHandler to I want pizza. Yum.

Those changes ought to be sufficient to prove that the model and the Lambda function are being updated. At this point, I have not touched a thing using the console, so everything should be in sync except for these three changes.

This time the command to “open greeter” does not work. Good, because I changed it to “open pizza maker.” And that works. I get back the message “I want pizza. Yum.”

Alright, so this seems to be working just fine.

What was blocking me before? A few things.

  1. ask deploy sets up my Lambda code in the us-east-1 region. I prefer to use us-west-2, but that gets the tool into a confused tangle. For now, my best bet is to let the tool do what it wants.
  2. I wanted to have a since role called ask-lambda-bot that I could reuse for all of my Alexa skills. The tool allows Lambda to create a new role that is specific to the skill. So every skill will get its own. It also uses a naming convention that is not quite to my liking, including the word ‘default’ because that’s the AWS profile being used. Weird, IMO. Also, too bad. Messing with the role messes up ask’s access, so for now, don’t do it.
  3. The developer console for creating and editing the skill’s interaction model is nice. Much easier to discover what the interactive console allows me to do than to real the extensive documentation of how ever aspect of the interaction model works, just to know what can be done. At some point, I’d love to spend my free time reading documentation. Even then, getting JSON structure into its expected form is an exercise in patience that exceeded my limits.
    • But going between the console and my code seems to have gotten things out of whack. I guess that’s why someone added the –force flag, which discovered at some point when I was already too frustrated to think straight.
  4. Yeah, at some point after beating your head against a wall, it’s good to walk away. Grab dinner, play with your kids or kittens or friends, and try again later. So far, I am having better luck today, now that I can see my mental blocks and walk around them.

So am I really working on Pizza Maker? No. That’s just a way to throw Alexa off of my scent. Secretly I’m working on Guess a Sum, the subject of my previous post.

I hope someone finds this helpful or interesting or at least entertaining. At least it was cathartic to get that off of my chest.

 

 

Alexa, What Do You Want From Me?

Invention is a struggle. It begins innocently enough.

I invented a game called Guess the Sum that involves at least two players. Each player thinks of a number within a given range, say from 0 to 10. Then the players take turns guessing the sum of all of the secret numbers. In a given round, each guess has to be unique. The player who is closest to the sum wins. It is possible to tie, with one player higher and the other lower than the sum by the same amount.

So let’s say you and I are playing. I might think of the number 8, and you might think of the number 2. You can go first. For your guess, you should say a number from 0 to 20. That’s the full range of possible sums of two numbers between 0 and 10. Make sense?

Say you guess 14. That means you think (or hope) my number is 6. Based on your guess and the fact that I know my number is 2, there is no way the sum can be 14. So I might guess 12, the highest possible sum. When we reveal our secret numbers, we learn that the sum is 10. I win.

For the next round, we would rotate who guesses first. That would keep things fair in terms of any first-guesser advantage.

Picking or changing your number after the other person guesses is a way to cheat. To avoid “accidents” where a player fails to think of a number first, having a way to secretly record the numbers makes sense. Slips of paper could do the trick.

Or a computer might help with that. I have considered hosting a Guess-the-Sum app, where people could sit around the same virtual table and guess their way through 10 or 20 rounds, chatting with each other on the side and having a grand ole time.

If you can trust your opponent, Guess the Sum can be played entirely by voice. That’s how I played with my daughter for years.

Coincidentally, last week the AWS Loft in San Francisco hosted Alexa Day. Amazon sponsors developer days to encourage people to write code that runs in their cloud and on their devices. For me, it’s usually a good chance to learn and see what is possible.

We were told to think of a useful skill to program. Instead, I decided to teach Alexa how to play Guess the Sum. That way, avid players would always have a willing opponent. I would make Alexa trustworthy by keeping the player’s secret number out of the guessing algorithm. Seemed like a good idea.

echo-dot-2937627_640

Echo Dot from Amazon

So I dusted off my Echo Dot, fired up my coding environment (VS Code), and made my first attempt at programming an Alexa skill. Three days of effort later, I am still trying to get the coding life cycle to work.

To give you a sense of the problem, imagine that someone gives you a jigsaw puzzle for your birthday. The box sports an eye-catching picture, and you anticipate the joy of putting it together. You clear off a table and dump out the pieces.

After about 10 minutes of flipping and sorting, you get the feeling that something is not quite right. While some of the pieces look like the picture on the box, some look like they are part of a different picture. A fair number of pieces are blank.

After 30 minutes, it’s pretty clear that you are dealing with two puzzles, along with a handful of mystery pieces that don’t seem to fit anywhere. You throw up your hands and walk away.

That’s kind of the feeling I’ve gotten so far with Alexa skill development. While the “getting started” tutorials are fine as far as they go, I have not quite figured out the right incantation to get beyond the first few steps on a skill of my own.

Apparently there are a few ways to go about this. Each starts out simply enough. One approach starts at the developer console.

  1. Create the skill in the developer console.
  2. Give the skill the invocation name: “guess the sum.”
  3. Add an intent. The skill needs at least one thing it can do to be activated for testing. In my case, I have two intents: learn the rules, and play the game.
  4. Create a Lambda function to handles intent requests. I am using Node 8.10, the latest Node that is available on Lambda.
  5. While creating the function, assign or create a role to the function, something that authorizes Lambda execution and write access to CloudWatch (for logging). Keeping things secure is a good idea.
  6. One last step is to connect the skill to the Lambda function and vice versa. Skill IDs and ARNs are copied back and forth, and that should do it.

Even the simplest Alexa skill handler uses modules, so writing JavaScript in the console is not going to work, as far as I know. That pushes me into my local IDE. Here’s where things start to unravel along this path. Nevertheless, I make my code changes, zip them up and upload using the AWS console.

Testing the Lambda function directly works fine. When I switch to the Test window of the developer console, nothing happens. Technically, something happens. A chat-like message bubble wags an in-progress dot at me, floating back and forth indefinitely while nothing is happening.

Alexa, what gives?

Also, the fact that I have to manually upload the zip whenever I change my code is going to be a problem. Better to solve that right away before I waste a ton of time.

If you know about dramatic irony, your literary antennae should be tingling. The phrase “before I waste a ton of time” is a classic bit of developer irony that means the developer is about to waste a ton of time figuring out how not to waste time.

That’s where my Friday went. And then my Saturday. I was heartily “saving time” by “getting things right.” In the end, nothing I tried worked entirely.

I quickly switched to an alternate path for programming a skill, which relies on the Ask command-line interface (ask-cli). This handy little tool seems to have everything a wily developer would need to create and deploy a skill. Super.

  1. Installed as a global NPM package, “ask” runs in a command prompt or terminal window. No mouse clicks required.
  2. You start with ask init, to set up the environment, including developer credentials. This command takes you through a login screen in the browser where you authenticate as ‘default.’ Now, is that my root user or my authorized developer profile? Or is it my separate developer login? Just keep moving.
  3. Then ask new creates a new project for your skill. If you know what you want to name your skill, the --skill-name parameter let’s you dictate it. Same goes for the name of the lambda function. Otherwise, the tool is happy to supply defaults.
  4. At this point, you should be able to issue ask deploy and have everything created for you in the cloud.

For me, this is where things get a bit slippery. Maybe it has to do with how much I have changed by the time I deploy.

Sometimes ask-cli tells me I does not have permission. Sometimes it tries setting up a Lambda function in the wrong zone (us-east-1 when I am clearly working in us-west-2) and complains that Lambda needs to be in the same zone as the skill. Sure, ask-cli, go ahead.

The documentation is plentiful and looks sufficient until you want to know why things aren’t working.

Alexa, stop teasing me.

Not one to give up too quickly, I pivoted to a hybrid approach.

  1. Start a skill in the developer console, going as far as setting up and connecting the Lambda function.
  2. On the command line, use the handy ask clone command to make a local copy of the skill model and associate code.
  3. Set up my handler with the required ask modules.
  4. Try ask deploy to update the code in the cloud.

At this point, something else goes wrong. It seems that the differences between what’s in the cloud and what’s on my computer are too much for Ask-cli, which mumbles something vague and gives up.

A few more pivots left me with a pile of false starts. I suppose I learned some things, but the one thing I didn’t figure out yet is how to set up the project environment so that it works from beginning to end.

Alexa, please work.

Despite my initial frustration, I believe this can work. After all, people have coded hundreds of thousands of skills to date for everything from daily horoscopes to auto-piloting submarines. Okay, I might have made that up. But from the hype, you would think that everyone is coding Alexa apps for anything you can imagine doing with your voice.

Oh, and now Amazon has new Alexa-powered devices that have screens. What the what?!? I thought the point was to interact with your ears and voice. Apparently vision is still one of the important senses.

Okay, deep breath. Just ignore that for now. I have to code Guess the Sum for voice only. That path is complicated enough.

Once my skill is working and tested by me, I’ll need to submit it for beta testing so I can load it into my little Dot and share it with my kids. After all, this is all about impressing my kids.

And once my kids are impressed, I need to apply to share my skill with the world. I think I can get money if people play it enough. And with some enhancements, I might be able to include in-skill purchases.

Yeah, that’s right. I can be making real money with my Alexa skills. Probably enough to fuel an entire business.

Now, where was I? Oh yeah, saving time setting up my development environment. This is gonna be good, I can tell.

Alexa, show me the money.

 

Why I Abandoned My Course About Game Design

Photo by Cindy Tang on Unsplash

What does it mean to fail?

We see failure in little things. My kids get loaded with standard-issue plastic junk at birthday parties. It’s colorful. It works for about 2 minutes. Then it breaks, left in a pile on the floor. Eventually the pieces find their way to the garbage.

Clothing can fail, revealing a bit more than intended. The accidental view may be stimulating or grotesque for the innocent bystanders. I’ll leave it to your imagination.

On a more serious note, failures of infrastructure are inconvenient and sometimes catastrophic. Think of the power going out or a gas line explosion.

Or think of what happens when a freeway bridge fails. We usually drive over bridges without considering the amazing benefit they provide. While the most famous bridges stand blatantly tall, with their elaborate suspension cables and lighted towers, most bridges inconspicuously support traffic from below.

I remember a bridge that went out on the New York State Thruway in the late 1980s. The river it spanned was swollen from the winter thaw and a heavy spring rain. The current washed out the supports, leaving a wide gap in both directions. A number of cars and trucks went over before someone realized what had happened and stopped traffic. According to reports, ten people died.

That bridge was along the over-the-river-and-through-the-woods path that we always took to visit my grandparents for the holidays. It’s shocking when something you have depended on fails so badly.

What else can fail? How about human failure? Schools threaten us with it. We can fail a test or a paper, fail a class, fail a grade, fail to graduate. Even if you manage to get through school without failing, you can still fail to accomplish anything important in life.

Even if you do accomplish something important, you can fail to spend enough time with your family. Or the important thing you accomplished can eventually fail. Apparently failure to drive the bridge supports deep enough in the 1950s is what led to its collapse some 30 years later.

So even those who manage to do incredible good, say by constructing time-saving, super convenient infrastructure, make mistakes that lead to failure.

Life is messy and unforgiving. Entropy is always against us. To survive, we find ways to cope.

If you read lofty quotes, you know the feel-good adage that failure only comes when we give up. Clearly that is not true in the sense that many failures occur despite perseverance. Nevertheless, that mindset is more productive than one of permanent hopelessness and despair. We need encouragement to keep going, to keep trying until things work out.

With that as a backdrop, let me tell you about my latest failure. It’s a good story, and I think you can use it to keep yourself going with whatever you are trying to do.

I took a course last year that teaches people how to make money selling online courses. Yes, that is something of a twist, that someone can sell a course about how to sell courses. You might expect the punchline to be that the whole things was a scam. That couldn’t be further from the truth.

Still, it’s not easy to find a subject that enough people will pay for to make an profitable business out of it. I tried to follow the formula. It goes something like this.

  1. Think of all of the ways to make money online. Put them into buckets, and realize that one of the best ways to make money is by selling knowledge. Better than ads, better than games (believe me!), better than large-scale software systems (for the solo-preneur, that is). Better than cat videos.
  2. Pick a topic that you know well enough to teach others who are less knowledgable. You just have to be more of an expert than the people you intend to teach. Since I have designed a few games, game design for beginners is a good choice.
  3. Find a market with a burning need or pain point. Blog about interesting things “where your market hangs out online,” and build up a list of followers. Get at least 100 of “the right people” to follow you. It’s not enough to have a bunch of your buddies. You need access to potential customers.
  4. Create a course that solves a burning problem of your market. Make it a work of art, a masterpiece that you can sell for about $50 with a clean conscience. You’re going to offer a money-back guarantee, so it needs to be solid.
  5. Launch the course, and enjoy months of success as people benefit from enlightenment and tell their buddies with similar needs. This is the part where you make money while you sleep. Notice all of the work it took to get to this point? No one said it would be quick or easy.

I did bits and bites of all of the steps, but I have to admit that I skimped on step #3. I never found my real market before creating my course. Only my imagined market of beginners who want to start designing games.

Now, it turns out that they really are out there. A couple of times a week, someone new will ask on Reddit how to become a game designer. Usually the advice is to “watch free videos on YouTube” and “just get started.”

My course has a few additional benefits over the standard advice. It covers the fundamentals and provides structure for coming up with game designs. By the time you finish the course, you will have designed your first game. I think most people could use the help, which is why they are asking for it.

So I charged ahead and spent a week sharing “interesting content” with folks on Reddit. With just a few posts, I managed to attract hundreds of readers and got one pre-order. That’s right. I only managed to get a single serious prospect for the course that I wanted to launch by the end of the month.

Figuring that it could just be a matter of time and marketing effort, I considered launching my course anyway. If nothing else, I would learn the remaining aspects of the business.

So, I moved on to step #5. That’s when I realized that hosting my course would cost about $35 per month. Heh, with my one student, I would be making about $27 at the discounted “introductory” rate. That came with a money-back guarantee and a promise for a full year of access. I would have felt better with at least ten prospects.

However, it turned out that the real kicker was that I also skimped on step #4. The videos I produced are packed with information, but my delivery skills are pretty bad. I failed to create a masterful work of art.

Originally, I figured I the lower price point would compensate for the lack of quality, but that was before I watched the free videos. They are so well produced, they made me blush. There’s no way I would charge for my rough-cut videos.

To recap, here’s a summary of the issues with Design a Game.

  • I have practically no one to sell to.
  • I don’t think anyone is suffering for not knowing how to start designing games.
  • My production quality is too low. I need a lot more practice to become a decent presenter on video. Also, my scripts could use some polish and pizzazz.
  • The economics are wrong.

Doing a better job and getting things right would easily take 3 to 6 months. Meanwhile, the mortgage payment keeps popping up, my kids need to eat, and life in California is expensive. In other words, I need a real source of income.

As it stands, enough of the elements are wrong that I decided it would make more sense to put the whole thing on hold while I put myself back on the job market.

Did I fail? Sure. Am I stressed about it? Nope. Much better to recognize what was happening and cut my losses than to continue stubbornly along the wrong path.

So that’s that, and life goes on.

Want to hear about what I am trying next? Subscribe, and I’ll write about it next time.

 

How Prototyping Saves My Sanity

bugatti-1612389_1280I am a firm believer in “good enough” mentality. When creating something, it helps to decide what would be good enough for the purpose you have in mind. Then you intentionally aim for that target. I would say that is the crux of any “lean” approach to writing software or starting a company. You do just enough to reach your objective and no more. That way you can avoid waste. Reasonable people can agree that avoiding waste is generally a good thing.

Still, the phrase “good enough” can be an excuse to avoid difficult work. It might also be used to rationalize being stingy, holding back what would benefit others. When striving to exceed expectations, an abundance mentality is more appropriate than squeaking by with something that is “good enough.”

To be effective, the phrase “good enough” has to be followed by the question “for what?”

If your purpose is to sell something, it has to meet a need that people will pay for. If your purpose is to gain notoriety or to build a legacy so that you are remembered for generations, you are setting the bar quite high. Whatever you create had better be outstanding.

As a solo-preneur—that is, someone working alone on bootstrapping a business around game design and development—my bar for good enough has to be relatively low. I am continuously testing ideas for viability. The ideas need to be good enough to gain even a little attention and to see what might work in a grander scale. I do not count on selling much in the early stages.

In my mind, ideas evolve quickly, and before long a vision begins to crystallize. Imagine with me that I have attracted thousands of followers. People are happy to use my amazing software and pay for it without hesitation. I have grow my company to a half-dozen people, and we are busy creating ever more software people love.

Hollywood has conditioned me to suspend my disbelief, so believing in my fantasies is easy. The hard parts are ignored, risks are dismissed. Would it be prudent to go all-in based on the movie of success in my mind? No, that would be crazy, or at least rather foolish.

Others would think so, too. They might whisper behind my back. You can almost hear the critique.

  • “Is that guy nuts?”
  • “What was he thinking?”
  • “He thought this drivel would draw an audience?”

On the other hand, all I need to do to keep my sanity is prove that the idea can work. Engaging in research and development toward in the pursuit of an idea is certainly reasonable. If it works, I’ll have something to show that others can understand. If I cannot find a way, or if it does not work as well as I imagined, I can use that evidence to adjust my idea or walk away from it.

With any non-trivial project, such as putting together an online game, I like to work in stages. The first stage is intended to answer a few questions.

  1. Can my idea work?
  2. What kind of effort will it require?
    • What skills?
    • What creative elements?
  3. Will the idea be interesting enough for others?
    • To try?
    • To pay for?

This first stage is a great time to build a prototype. Our ideas can be full of magic that needs to be turned into moving parts based on physical reality. A good prototype does the trick.

An Analogy

Think about a car manufacturer who wants to develop its first electric car. Does the company sell the first car it produces? No. Does it even have an assembly line for the first car? No. Although the car company knows how to produce cars, an electric car is fundamentally different than those that burns fuel. That requires some new ideas.

A team in a research lab might start by assembling by hand a wheel, an axle, an electric motor, and a battery. Someone might write software to control the motor. Although far from being a complete car, this is a basis for learning how an electric car might work.

Once those pieces are working together, the team might add a brake, updating the wheel and controller to accommodate. The team might try cutting-edge technology as well as something more traditional. In fact, they would consider the technology choices for each component, whether to stick with what has worked, to try something ground-breaking, or to invent their own technology specifically for this new purpose.

They probably have things wired to test and measure their attempts. Do the breaks get too hot? Can they overpower a runaway motor? Can a bug in the controller software lead to a safety issue?

The point is to learn, to push the boundaries, and to prove what can work. This is the essence of prototyping. See if your ideas can work, get a sense of the effort involved, and give yourself a way out before spending too much on full development and the trappings of a production launch.

Decisions about paint colors and interior fabrics can probably wait. Adding a rocket booster is probably also out of scope, as tempting as it might be to explore.

A True Story

Back in December, I wrote and launched my first release of StoryTime, which is a game platform for writing and playing interactive, text-based adventures. The first release was good enough in about two weeks.

By now you know to ask, “Good enough for what?”

Glad you asked. My target was to launch a “reader” application for playing story-games, with one complete story loaded and ready to play. The launch was merely a matter of hosting the system where anyone with an Internet connection could try it.

I did that.

Then I needed a way to register authors, so I added a database to the back-end and hooked up an identity provider to handle sign up and authentication. That work included a feature for players to opt-in and become authors.

Once it was working, I released it.

The release was nothing fancy. Real authors would probably want to provide a lot more information about themselves, like the write-up that you find on the back of a book cover. I only wanted to show that I could save any information about the author. What I had was good enough as a proof.

Then I added the Writing Desk, where authors go to write their story-games. It’s slightly more complicated than using a word processor because you have to hook up the scenes in a certain way. However, there’s no coding involved for the author. Just type and save.

So I released that.

The Writing Desk also lacked features that would make for a carefree user experience. One problem was the way the story was organized. The layout made it possible to get to everything but not necessarily intuitive. Also, the editors lacked feedback cues, and without auto-save, it would be easy to lose work.

Still, it was good enough to show how all of the pieces of a story-game could be written and connected.

Then I added a way to publish story-games. That promotes a game into the library where anyone can find it and try it out. Although the UI had a couple of refresh issues where updates were not being displayed immediately, nothing was broken fundamentally.

So I pushed that out, too.

The publishing step involves categorizing the story-game by assigning a rating (for age-appropriateness) and one or more genre. While capturing the information was import to show how stories might be grouped and searched, new features are needed to make use of the information. That didn’t stop me from releasing.

And there it stands, a working example of a simple gaming platform. Is it good enough? Well now, that depends, as you know. Good enough for what?

If I believed the movie in my head, the fantasy that I was creating something thousands would love and pay to play, my only option at this point would be to break down and cry. StoryTime is nowhere near good enough for commercial purposes.

Luckily, I have a mindset that allows me to appreciate what I have done and use that to understand what I could do next.

What I have done is to build a prototype of the gaming system I imagined.

  • The prototype is not colorful, at least not in an artful sense. At least I used Bootstrap for styling, so it isn’t horrible. Unless you don’t like Bootstrap.
  • It is not elegant. As I mentioned, it’s pretty easy to lose work, which is about the worst thing that can happen to a writer.
  • The library is still nearly empty. It’s got the one story-game that I wrote back in December. I have been too distracted to write another. Also, droves of writers have not decided to invest irrationally in a game platform without players, an ecosystem, or an obvious payout. Go figure.
  • Mostly players don’t want to become writers. In fact, players want graphics. A text-only game is a tough sell these days.

A game designer ask if StoryTime could be used as the story line in Unity, a popular game platform. That’s a good idea. So perhaps what I have done is assemble a new mechanism that could be built into a larger system. Like figuring out a drive train based on electricity.

As a stand-alone gaming platform, StoryTime could use so many more features. What about illustrations, at least for the cover art? How about collaboration? Shouldn’t there be a review process to make sure what’s being published meets community standards?

Say authors actually used StoryTime to create alternate-universe games. How would games be sold? What’s the business model? Some companies have made this work. Others have closed their doors.

In short, the gap to realize my dream for StoryTime is huge. Finishing will involve a lot more work. It will also take more talent than I have. To see it through, I will need that six-person team. And I still don’t know if would be worth it.

Meanwhile, something else happened that would be enough to drive a normal person bonkers.

Who Moved My Technology Cheese?

The last release of StoryTime was in April. Since then, I have been busy with other concerns. As I returned to my little coding project last week (now July), I found what has become a familiar scene. The software still runs, but everything it relies on has moved. Allow me to explain.

When I started this incarnation (let’s call it the 3rd go) of StoryTime, I made some choices for the underlying software technology. First, I decided to go 100% JavaScript. StoryTime uses ReactJS and its ecosystem of modules for single-page-app support. On the back end, StoryTime offers a service with a REST API defined using Open API 3.0 (a.k.a. Swagger). The service uses Express on NodeJS 8. That connects to a PostgreSQL database where the stories and data are kept. As any React developer might guess, the app uses React Router for navigation and Redux to manage UI state. I also chose Bootstrap for styling, as I mentioned before.

Everything is written using es6+. That’s a relatively new form of JavaScript that anyone serious has been using for a while, with Babel transpiling down to something that older Web browsers can understand. Of course, it’s all built by Webpack, with as many unit tests as I could remember to write (not enough).

The whole thing is hosted on Heroku, which had just introduced pipelines. So I check my code into Git and pushed to GitHub, where Heroku notices the update, pulls it down and builds it on my staging server in the cloud. After that, I try my changes in staging, which is as close to production as you can get. In fact, when things check out, I simple move that build to production using a little button on the pipeline. Easy.

Also, I installed PaperTrail in order to see the last few days of logs. After all, I want to know when people are using the game.

Even if you don’t write software for a living, you can see that there are a lot of parts. Many of these parts are moving, too, in that they are supported by communities of active developers who keep changing things.

So I am used to having to upgrade components rather frequently. But stepping away for a bit changed my perspective. Here are a few of the shocking revelations.

  • JavaScript is losing favor to TypeScript.

TypeScript is a superset of JavaScript that introduces type safety, a much-needed measure of control, to JavaScript. Now you can ensure that an object conforms to the shape that is expected. All the flexibility of a scripting language with the safety of something that gets compiled, like C, C# or Java.

  • Redux sucks.

Redux is the “recommended” approach to managing client-side state. A Redux store is a good place to keep facts that you want to show in the UI. For instance, the fact that an edited scene needs to be saved might be recorded in a Redux store.

The truth is that the Redux approach is hard. I’m not just whining about it. It adds overhead and comes with a mental tax. I waited as long as I could before adding it into StoryTime because I knew that it would slow me down. Now every time I return to add something else to the store, I have to remember the gymnastics to make it happen.

  • Bootstrap looks horrible.

I mean it’s okay, but not really. Certainly not with my limited skill at styling. Also, I tried using reactstrap with its React-ready components for applying Bootstrap styles, but the documentation was insufficient for someone in a hurry. I had to keep looking at their code to know what was ready and how to use it. Bah.

  • Node is on to version 10.

You can still use 8, although it’s now on long-term support (LTS). Might as well start thinking about upgrading and what that will mean.

  • auth0 has a pricing model that will crush me beyond 6,000 (or so) users.

I knew this going in, but figured I would adjust if I ever got close to that level of adoption.

Any one of these gaps might not be worth a full-scale rewrite. Yet combined with the realization that I have been building a prototype and that no one has even tried to write a story-game yet (aside from my dad. Thanks, Dad!), I feel completely at ease walking away from this PROTOTYPE and starting over with a better idea.

Once again, prototyping has saved my sanity. I get to chalk it up to learning and decide what to try next.

 

 

See What You Can Do With These Game Ideas

A couple of posts ago, I promised to share one of my game ideas. This is my post to make good on that promise. Even better, let’s take a look at two ideas.

My game ideas tend to originate from either a twist on an existing game or some concept that can be made into a game. As a starting point, I think of ten ideas, anything goes. Most of them probably won’t amount to much. By coming up with ten ideas every day or once a week, eventually one of them is bound to be worth pursuing.

These are two that I think merit a closer look.

Pyramid

If you have made it to your 20s, you have lived long enough to be aware of pyramid schemes. How about turning that into a game?

Here’s the premise. Anyone is allowed to start a pyramid and be the boss, and players can join any of the active pyramids. The object is to convince players to join your organizations, which requires an investment of points. Those who join become recruiters who try to convince others to join.

Each player collects points based on a portion of the points collected below that player in the organization. The lower you are in the pyramid, the smaller the portion. At some point, it wouldn’t make economic sense to join, but recruiters can still do their best to persuade new joiners.

Players can participate in any number of pyramids as long as they have enough points to “invest.”

At some point, the top boss either makes the call to shut it down, say when growth starts to stall, and heads for the Bahamas. Or he or she gets caught by the authorities and goes to prison. Maybe the closest lieutenants have to pay a fine. Everyone else just loses their investment.

That’s the general sketch. Indeed, it might seem a little sketchy. Perhaps the point of the game is to demonstrate the problems with pyramid schemes, or to teach how to recognize them.

On the other hand, it might offer a way for the unscrupulous to practice without legal consequences. Also, people might also find a way to use the game as a proxy for a real-life pyramid scheme, where player points convert to money. That would be illegal (at least in the United States) or dangerous.

The game is suited for online play because it requires a lot of players the way I described it. In another form, the game could be laid out on a board and played in a way that’s similar to the Game of Life. Some of the spots allow you to form or join a pyramid, some add followers or receive regular payouts, some are where you get exposed and lose everything. If you make it to an undisclosed private island to live the life of luxury (and lonely isolation), you win.

Good idea or DOA? Alright, take it or leave. Let’s look at another.

Entrepreneur

This game is designed to give players a sense of the life of an entrepreneur. The premise is that you have this great idea for a business, and you want to launch a company and take it public.

You have to advance through levels, each of which gives you a baseline 10% chance of continuing. That’s a 90% chance of being wiped out each time you try to advance. You also have the choice to cash out once you complete the level you are on. Cashing out might cost you but probably leaves you with some rewards.

Maybe your odds are impacted by decisions you make. Choosing a narrow market, expanding in a way that builds on existing assets, getting the right professional help, and making good deals with helpful partners would all improve your odds. You can also make bad choices that lower the odds. Hmm, I can probably come up with a few of those, too.

Is this a board game where you have to go around some number of times? Is it based on decks of cards, one specific deck per stage?

I can imagine using dice to determine outcomes. Want to make a deal? A roll of 10 means it’s perfectly executed. A 5 through 9 means it goes through but is less effective than hoped. Roll a 2, 3 or 4 and the deal is off. A 1 means the deal is shady and costs you in the long run. That’s got the feel of an RPG.

Entrepreneur might be well-suited as an online multi-player game. Each player is busy trying to build his or her corporate empire. The “daily news” feed could be filled with the wins and losses of the other players, deal offers, and so on. Perhaps specializations develop: some want to build companies, others want to be venture capitalists. Maybe the bankers and lawyers are all bots with a range of programmed skills and ethics.

You get the idea, right?

Ta Da

So there you have it. Two seeds. Two kernels. Two ideas that might be developed or morphed into any number of interesting games.

If you liked those, let me know in the comments. I can share a few more someday.

If you are new to game design and want help getting started, check out Design a Game. It’s got all of my best thinking on the subject of game design. By the end of the course, you’ll be coming up with playable ideas of your own.

Finally, remember to subscribe because it shows me that you are interested.