HTML and CSS Reference
In-Depth Information
catch (e) {
alert("data not saved, error given: "+e);
}
This is a general technique that will try something, suppress any error message, and if there is an error, it
will invoke the code in the catch block.
Note: This may not always work as you intend. For example, when executing this application on
Firefox directly on a computer, as opposed to a file downloaded from a server, the localStorage
statement does not cause an error, but nothing is stored. This code does work when the HTML file is
downloaded from a server using Firefox and the creation script works both as a local file and when
downloaded using Chrome. The two-script version must be tested using a server for each of the
browsers.
Retrieving the information works in a corresponding way. The code extracts the name given by the player
to set the variable lsname and then uses
swalls = localStorage.getItem(lsname);
to set the variable swalls . If this is not null, we use the string method split to do the opposite of join:
split the string on the symbol given (we split at every semicolon) and assign the values to the successive
elements of an array. The relevant lines are
wallstgs = swalls.split(";");
and
sw = wallstgs.split("+");
Next, the code uses the information just retrieved and the fixed information for wall width and wall style to
create a new Wall object:
curwall = new Wall(sx,sy,fx,fy,wallwidth,wallstyle);
Finally, there is code to add curwall to both the everything array and the walls array.
Radio buttons
Radio buttons are sets of buttons in which only one member of the set can be selected. If the player
makes a new choice, the old choice is deselected. They are an appropriate choice for the
hard/moderate/easy selection for this application. Heres the HTML markup in the <body> section:
<form name="gf" onSubmit="return getwalls()" >
<br/>
<input type="radio" value="hard" name="level" />Hard <br/>
<input type="radio" value="moderate" name="level" />Moderate <br/>
<input type="radio" value="easy" name="level" />Easy<br/>
<input type="submit" value="GET maze"/><br/>
</form>
 
Search WWH ::




Custom Search