Simple Debugger

version 1/080105 by Michael Hilborn

  • Home page
  • Beginning
  • Previous
  • Next

  • Example: ** Firefly - Using the simple debugger to track Inform 7 counters and events.


        Include Simple Debugger by Michael Hilborn.

        [When writing interactive fiction, we almost invariably want some kind of timing mechanism or counter to go off. Inform provides this ability, but there is no way to view how many turns or minutes are left in a counter. Here we demonstrate how the debugging tool can do this for us. It takes some effort.

        Here's the scenario: The player is trapped in a cell where the lights go off every five turns. Fortunately, the firefly in the player's possession lights up the room until the power comes back on in another five turns.]

        [At the beginning of play, we activate the debugger and schedule the first power outage.]
        When play begins:
        [initialize debugger, activating object debugging, activating general debugging;]
            schedule the power outage.

        [The counter is a global variable tracks and resets the number of turns left before the power goes on or off.]
        Counter is a number that varies.

        [When scheduling a power outage, we first reset the counter to 5. If we're debugging, then we print a message stating that the power is going to go out.]
        To schedule the power outage:
            change counter to 5;
            if we're debugging begin;
                say "// Power goes out in 5 turns.";
            end if;
            the power goes out in four turns from now.

        [When the power goes out, we reset the counter and, if we are debugging, print an alert. The rest of the code darkens the room, ignites the firefly, and sets the power to come on in five more turns.]
        At the time when the power goes out:
            change counter to 5;
            if we're debugging begin;
                say "// Restarting the power in five turns.";
            end if;
            say "The lights flicker, then go out... again. The firefly, however, fills the room with a green glow.";
            now the firefly is lit;
            now the Cell is dark;
            the power goes on in four turns from now.
        [When the power goes out, we print the appropriate message, turn the lights on, turn off the firefly, then schedule another power outage.]
        At the time when the power goes on:
            say "The lights of the cell flare back on.";
            now the firefly is unlit;
            now the Cell is lighted;
            schedule the power outage.

        [During each turn, we need to decrement the global counter, then, if we're debugging, print out that counter to show the player how many turns are left until the counter times out.]
        Every turn:
            change the counter to counter - 1;
            if we're debugging, say "// Countdown: [counter]."

        [And the rest is mostly window dressing.]
        Every turn when the firefly is lit:
            say "The firefly casts a pale green glow."

        Cell is a room. "This is where the crew tossed you after they discovered you hiding in the cargo bay. The big guy wanted to shoot you, but the doctor and the engineer would have nothing to do with it. That engineer--she's a cute one, and obviously doing something with the ship's engine. The lights flicker out every five minutes or so."

        The player is holding the specimen jar. The specimen jar is closed.

        The firefly is an animal in the specimen jar. The specimen jar is transparent. The firefly can be lit. The firefly is unlit.

        Instead of examining the firefly:
            say "A small insect that ignites its posterior when the lights go out. Very rare on some planets. And very priceless.";
        Test me with "debug / i / x jar / x firefly / wait / g / g / g / g / g".