Fuse : Event
| [Previous] [Main] [Next] |
Defining the dynamite this way probably isn't a very good idea, however, since using a Fuse on in it this way cuts across the mechanism already provided by the Candle class. So, once you've experimented with implementing a Fuse on the dynamite, I suggest you remove it again and put the dynamite back the way it was (simply remove or comment out the code in bold in the above code fragment). If this change were retained, other changes would also be needed to make everything work properly, but we shan't be pursuing those; it's better to keep the dynamite as it was before.
For our second example we'll create a Fuse and a Daemon on the same object, though for the moment we'll concentrate our attention on the Fuse. A solid gold tablet, such as we've placed in the plinth of the statue, would be pretty heavy to carry around, and indeed it's the heaviest portable object (as defined by its weight property) that we've defined in the game. Rather than create an old-fashioned inventory puzzle by limiting the total amount of weight the player character can carry (so that, for example, the player character would have to drop everything else in order to carry the gold tablet, and arrange to distribute light sources along its path, which would all be pretty tedious) we'll limit the number of turns the player can carry the gold tablet before putting it down to take a rest. We'll use a Daemon to limit how long the player character can carry the gold tablet for, and a Fuse to simulate his or her recovery. We'll add a carried property to goldTablet which will hold the number of turns for which the tablet has been carried. Once this reaches 3 the player character becomes too tired and is forced to drop the tablet. At this point we set a fuse that is fired after three turns (provided the player leaves the gold tablet alone in the interim); when the fuse fires three turns later, it simply resets goldTablet.carried back to zero (which would allow the player character to pick up the gold tablet and carry it for another three turns).