I'm implementing the extra feature for pset8 where the user has only a limited amount of time to play the game before it ends.
My aim is to load the window and Google Earth, popup an alert stating the rules, start the game, and then load another popup when the timer runs out. I decided to do this in the window.load()
function:
$(window).load(function() {
// listen for keydown anywhere in body
$(document.body).keydown(function(event) {
return keystroke(event, true);
});
// listen for keyup anywhere in body
$(document.body).keyup(function(event) {
return keystroke(event, false);
});
// listen for click on Drop Off button
$("#dropoff").click(function(event) {
dropoff();
});
// listen for click on Pick Up button
$("#pickup").click(function(event) {
pickup();
});
//load application
load();
//alert player of game rules
alert("Sample Game Rules");
});
As you can see, at the end, AFTER the load()
function is called, I alert the user of the rules. However, this alert comes up BEFORE load()
has loaded up the map. When I put in
window.setTimeout(end_game(), 10000);
I have the same problem. Instead of waiting until Earth has loaded, the alert displayed by end_game()
is immediately displayed, without even a 10 second delay as is expected.
What am I doing wrong? Have I misunderstood alert()
?