Simple text game, part 2

This is part 2 of a simple text game tutorial.

Using text services
The current version blindly accepts all words. That's not good. Instead, let's use the server-side dictionary service to validate them. You may wish to reference GameControl and ServicesSubControl for more info on the services we will use.

Let's change the keystroke handler as follows:

/** Called when the user presses a key inside the inputField control. */   protected function keyEventHandler (event :KeyboardEvent) :void {       if (event.keyCode == 13) {  // user hit Enter if (_control.isConnected) { _control.services.checkDictionaryWord ("en-us", null, _inputField.text, processWord); } else { _responseField.text = "Error: disconnected."; }           _inputField.text = ""; } else { // any other key just clears the message box _responseField.text = ""; }   }

You may notice several interesting things here. First, the game now checks for server connection before making the service request (if we try to do this without checking, it'll cause an exception). But it also means that the game no longer runs stand-alone. We'll deal with that below.

Second, we specify the locale as "en-us" to check against the American English dictionary. That's the only one we have right now. Sorry. :-)

Third, when calling checkDictionaryWord, we don't get a return value from that function call. It calls the server to do the check, which is not instantaneous - we will get a result later, but we can't be sure when, and we certainly shouldn't pause the game while we wait for this result. :-) So instead, we pass in processWord, a callback function closure, which will be called with the results once they become available.

Uploading
Since we need a server connection, we can't just run the game locally anymore. I mean, we can, but because of the isConnected check, the game will just print out an error message. (Go ahead, try it. :-) (Actually, the game will work fine; apparently the sdk has changed behavior since this tutorial was originally written. However, you wanted to learn how to upload your game, didn't you?)

To test this game, upload it to the server. Log into Whirled and follow these directions:


 * 1) Choose Games &rarr; My Games to see the games you have uploaded.
 * 2) Click the Create button to get the game uploading interface. [[Image:Games-Create_Game.png|none|425px|thumb|The game uploading interface.]]
 * 3) Use the default "Parlor Game" selection.
 * 4) Under Game Name, type the name of your game.
 * 5) Under Thumbnail Media, click Browse..., and select your image file. This thumbnail is used to represent the game in My Games.
 * 6) Under Client Code, click Browse..., and select your .swf file in the file system browser that appears. When the file has finished uploading, you should see a SWF id show up (e.g. 031c99dbf403923daad884fb562bd7f0d83d555x.swf) in the Client Code section.
 * 7) Confirm that you own the copyrights to the item or have authorization to upload it.
 * 8) Click on the Save button and your browser will switch to the Edit Game interface where you can configure your game.

See uploading games and options for games for more complete directions.

To test play your game to make sure the upload worked, click on it, and then click on Play. It should give you different messages based on the words you enter.

By the way, if you make changes and rebuild the game, you don't need to delete the old game and re-upload everything. Instead, just edit the existing game, reupload the updated game media and click on Save.

Next: we will add scoring, and discuss multiplayer testing.

= Next Steps =


 * Simple text game, part 3
 * Back to Creating Games