Simple text game, part 2
| ActionScript Tutorial |
|---|
| Create a simple mulitplayer game. |
| Difficulty Level |
| Medium |
| Requirements |
| Other Information |
| Previous: Simple text game, part 1 Next: Simple text game, part 3 |
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:
<actionscript>
/** 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 = "";
}
}
</actionscript>
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
- Main article: Uploading games
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:
- Choose Games → My Games to see the games you have uploaded.
- Click the Create button to get the game uploading interface.
- Use the default Parlor Game selection.
- Under Game Name, type the name of your game.
- Under Thumbnail Media, click Browse..., and select your image file. This thumbnail is used to represent the game in My Games.
- 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.
- Confirm that you own the copyrights to the item or have authorization to upload it.
- 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.