Game Development Reference
In-Depth Information
Figure 20-1. The level menu screen in Penguin Pairs
Dealing with Errors
Before you finish this chapter, let's talk a little more about dealing with errors in JavaScript.
Particularly when games get more complex, you need to think about what happens when an error
occurs. To give a concrete example, in the get method of the GameStateManager class, you return a
game state only if the identifier passed as a parameter falls in the range of the elements in the array:
GameStateManager_Singleton.prototype.get = function (id) {
if (id < 0 || id >=this._gameStates.length)
return null;
else
return this._gameStates[id];
};
 
Search WWH ::




Custom Search