Countdown

This is a countdown that will appear below the compass. When the countdown gets to zero, the game ends.

http://textadventures.co.uk/games/view/7xw5218ilegsxzbon37k9q/countdown

The counter is in JavaScript, running in the browser, so not using the Quest timer system at all. This means it can be fast, and will display tenths of a second. Events are triggered at various points (every 30 seconds, but it could be at any arbitrary time), with the final event at time zero terminating the game.

This is a complete example game (there is not much to it apart from this system). You cannot actually do anything except look in wonder at it for 2 minutes, after which is will end.

<!--Saved by Quest 5.6.6108.15891-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="countdown">
    <gameid>ada9e4dc-f929-41c3-94c5-4d942e0cd6c4</gameid>
    <version>1.0</version>
    <firstpublished>2016</firstpublished>
    <js><![CDATA[
    <div id="clock">
      <table>
        <tr>
          <td style="font-family:monospace;font-weight:bold;font-size:24pt;text-align:right;" id="time"></td>
        </tr>
      <table>
    </div>
    <script>
      d = new Date();
      startTime = d.getTime() + 2 * 60 * 1000;
      myVar = setInterval(myTimer, 100);
      
      event1 = { time: 90000, message: "This happened", done: false };
      event2 = { time: 60000, message: "Then this", done: false };
      event3 = { time: 30000, message: "And then this!", done: false };
      event4 = { time: 0, message: "stop", done: false };
      
      events = [ event1, event2, event3, event4 ];

      function myTimer() {
        timeNow = new Date();
        lapsed = startTime - timeNow.getTime();
        if (lapsed < 0) {
          $('#time').html("--:--.-");
          clearInterval(myVar)
        }
        else {
          minutes = Math.floor(lapsed / 60000);
          sMinutes = "00" + minutes;
          lapsedSeconds = lapsed - minutes * 60000;
          sSeconds = "0000" + (Math.round(lapsedSeconds / 100) / 10).toFixed(1);
          $('#time').html(sMinutes.substr(-2) + ":" + sSeconds.substr(-4));
        }
        for (var i = 0; i < events.length; i++) { 
          if (!events[i].done && events[i].time > lapsed) {
            ASLEvent('HandleEvent', events[i].message);
            events[i].done = true;
          }
        }
      }      
    </script>
            ]]></js>
    <roomenter type="script">
      JS.addText (game.js)
      JS.eval ("$('#clock').insertAfter($('#compassAccordion'))")
    </roomenter>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="HandleEvent" parameters="s">
    if (s = "stop") {
      finish
    }
    else {
      msg ("A message from the timer: " + s)
    }
  </function>
</asl>

I'm sure this will prove very useful for many, but it looks like Hieroglyphics to me. I could spend a lifetime trying to learn JS and never get there.

Anyway, I kind of wish I'd been a bit more patient and waited for this before submitting a game that uses Quest's unreliable wait scripts. It would have needed many tweaks before it did what I want, but I'm sure it could have been adapted.


It was your requests that inspired it.


I suspected so and hope my first sentence didn't come across as ungrateful. I hadn't realised you were planning this and I was growing impatient to get my game finished.

Out of interest, would this have been easy enough to tweak so that it does what my game does now, namely do away with the countdown display and have a sound/message triggered at intervals, then move the player to a game over room at zero?


Yes.


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums