Using Parameters
On the Game
object, the method getParameter()
retrieves the value of a parameter. The method takes a string as an argument, which is the name of the parameter. The method returns the value of the parameter.
If the parameter is not defined, the method will throw an exception.
In practice, use the getParameter()
method in place of a hard-coded value. For example, a previous example allowed three clicks on a button, and the fourth click ended the example. The number of clicks was hard-coded as 3.
If the allowed number of clicks was defined in the parameter schema as allowed_clicks
, then the code in the event handler would change from
if (helloCount === 3) {
square.hidden = true;
instructionsLabel.hidden = true;
tooManyLabel.hidden = false;
}
to
if (helloCount === game.getParameter("allowed_clicks")) {
square.hidden = true;
instructionsLabel.hidden = true;
tooManyLabel.hidden = false;
}