There was another recent question about the use of Daemons where I suggested the use of my ResettableEvent class. You might find it a useful tool even if you’ve got your current daemon situation under control.
The class takes care of a lot of busy work for you, so the main thing that you do is define an RDaemon somewhere, and write code in its events method. The class keeps a counter for you, so in your code you can just query the ct property, for instance in a switch block. You don’t need to create a separate Fuse, you can just end the game when the daemon reaches the ct that you want.
Vis-á-vis calling the daemon with “arguments”, yes, you’d still do something similar to Eric’s suggestion and probably store that argument in a property. The code would look something like this:
// can be defined top level or as a nested object
// somewhere
delayedDeathDmn : RDaemon
cause_ = nil
die(cause) {
cause_ = cause;
start;
}
events {
switch (cause_) {
case 'plague': plagueEvents(); break;
case 'snakebite': snakebiteEvents(); break;
case 'poison': poisonEvents(); break;
}
}
plagueEvents() {
switch (ct) {
case 2: "(boils are developing)"; break;
case 4: "(you can barely walk)"; break;
case 6: [end game with death message]; break;
}
}
snakebiteEvents() { ... }
;
With this definition, you only need to call delayedDeathDmn.die('plague') at the appropriate point in your code. The way ResettableEvents work, you can also get an antidote and call delayedDeathDmn.reset before the counter hits death count, and all the underlying cancellations will be taken care of, and the daemon is ready to start from 0 again if you get another exposure to the plague.
Of course, depending on how much you want to do with it, you might just want to skip the “arguments” and make
plagueDmn : RDaemon
...
;
snakebiteDmn: RDaemon
...
;
where then you would simply call plagueDmn.start or snakebiteDmn.start as appropriate, and your definitions can dispense with the cause_, die(), and xxxEvents members, just defining events directly.