I would like to write a daemon that prints spooky messages every 12
turns throughout the game without stopping. If it can start a few
moves into the game, all the better.
I assume I need to use a daemon and a switch. But I don't know where
to start. I don't understand the syntax or structure.
And do I attach the daemon to another object such as the startroom? Or
will it be an independant object?
Here's how ridiculously lost I am:
daemonID = new Daemon(self, &daemon, 12)
daemon
switch(++messageCount)
{
case 1: "You hear a faint noise, as if someone just ran past you.";
break;
case 2: "Did someone just whisper something? That's strange... ";
break;
case 3: "You hear heavy breathing. "; break;
case 4: "You just had a funny feeling in the pit of your
stomache."; break;
case 5: "You feel as though someone is watching you."; break;
case 6: "You here a slight cough."; break;
case 7: "The sound of a broken twig echoes in the distance.";
break;
case 8: "Did you hear that?!?"; break;
case 9: "A breeze blows across the back of your neck"; break;
case 10: "You smell the faint odour of cigarettes"; break;
case 11: "A flash of black appears before you but before you can
focus, it's gone"; break;
case 12: "You hear slight rustling, possibly a footstep, but you
turn and there is noone there."; break;
default: "There's a slight chill in the room. "; break;
}
}
;
I've read all of the TADS3 manuals. Even cutting and pasting the
dripping daemon didn't work! Sorry for my ignorance...
Reg
Do you mean once every 12 turns, or a repeating cycle of 12 messages,
one of which will fire every turn? I don't think the latter is what
you're after, but you're close to having it worked out, so let's start
there. Here's a basic way to do it, based on your code.
What I'm doing is, first, I attach the daemon to the me object, which
insures that its messages will always be printed. (If the daemon is
attached to an object in a room, when the player leaves the room you
have to do a special trick to get the daemon's message to print.)
Second, I added a showIntro method to gameMain, and started the daemon
there.
Note also the safety measure -- you should always check to make sure the
daemonID is nil before you attach it to a new daemon.
// begin code
gameMain: GameMainDef
initialPlayerChar = me
showIntro () {
"Welcome to my game!<p> ";
if (!me.atmosDaemonID) me.atmosDaemonID = new Daemon (me,
&atmosDaemon, 1);
}
;
startRoom: Room 'Start Room'
"This is the starting room. "
;
+ me: Actor
atmosDaemonID = nil
messageCount = 0
atmosDaemon {
switch(++messageCount) {
case 1: "You hear a faint noise, as if someone just ran
past you."; break;
case 2: "Did someone just whisper something? That's
strange... "; break;
case 3: "You hear heavy breathing. "; break;
case 4: "You just had a funny feeling in the pit of your
stomach."; break;
case 5: "You feel as though someone is watching you."; break;
case 6: "You here a slight cough."; break;
case 7: "The sound of a broken twig echoes in the
distance."; break;
case 8: "Did you hear that?!?"; break;
case 9: "A breeze blows across the back of your neck"; break;
case 10: "You smell the faint odour of cigarettes"; break;
case 11: "A flash of black appears before you but before
you can focus, it's gone"; break;
case 12: "You hear slight rustling, possibly a footstep,
but you turn and there is no one there."; break;
default: "There's a slight chill in the room. "; break;
}
if (messageCount > 12) messageCount = 0;
}
;
// end code
This cod prints a different message every turn, which will get
mind-numbing for the player before very long. If you want a random
message from a list, and you want to see it once every 12 turns (which
is arguably better game design), here's a better way to write the daemon:
+ me: Actor
atmosDaemonID = nil
atmosMessage: ShuffledEventList {
[
'You hear a faint noise, as if someone just ran past you. ',
'Did someone just whisper something? That\'s strange... ',
'You hear heavy breathing. ',
'You just had a funny feeling in the pit of your stomach. ',
'You feel as though someone is watching you. ',
'You here a slight cough. ',
'The sound of a broken twig echoes in the distance. ',
'Did you hear that?!? ',
'A breeze blows across the back of your neck. ',
'You smell the faint odour of cigarettes. ',
'A flash of black appears before you but before you can focus,
it\'s gone. ',
'You hear slight rustling, possibly a footstep, but you turn
and there is no one there. ',
'There\'s a slight chill in the room. '
]
}
messageCount = 0
atmosDaemon {
if (messageCount++ == 12) {
atmosMessage.doScript;
messageCount = 0;
}
}
;
With this code, the atmosDaemon will call the atmosMessage's doScript
method once every 12 turns, and doScript will choose a random message
from the event list. Note that in single-quoted strings, apostrophes
have to be preceded by backslashes.
Hope this helps!
--JA
>
> I assume I need to use a daemon and a switch. But I don't know where
> to start. I don't understand the syntax or structure.
> And do I attach the daemon to another object such as the startroom? Or
> will it be an independant object?
>
> Here's how ridiculously lost I am:
>
> daemonID = new Daemon(self,&daemon, 12)
Do you mean once every 12 turns, or a repeating cycle of 12 messages,
// begin code
switch(++messageCount) {
case 1: "You hear a faint noise, as if someone just ran
past you."; break;
case 2: "Did someone just whisper something? That's
strange... "; break;
case 3: "You hear heavy breathing. "; break;
case 4: "You just had a funny feeling in the pit of your
stomach."; break;
case 5: "You feel as though someone is watching you."; break;
case 6: "You here a slight cough."; break;
case 7: "The sound of a broken twig echoes in the
distance."; break;
case 8: "Did you hear that?!?"; break;
case 9: "A breeze blows across the back of your neck"; break;
case 10: "You smell the faint odour of cigarettes"; break;
case 11: "A flash of black appears before you but before
you can focus, it's gone"; break;
case 12: "You hear slight rustling, possibly a footstep,
but you turn and there is no one there."; break;
default: "There's a slight chill in the room. "; break;
}
// end code
Hope this helps!
--JA
>
> I assume I need to use a daemon and a switch. But I don't know where
> to start. I don't understand the syntax or structure.
> And do I attach the daemon to another object such as the startroom? Or
> will it be an independant object?
>
> Here's how ridiculously lost I am:
>
> daemonID = new Daemon(self,&daemon, 12)
--JA
Fantastic! Not only is your code and explanation clear but you even
fixed my apostrophes!
I added it to my game and it works and provided the finishing touch!
Thank you so much for your help!
I'm one happy girl now!
Reg
One more big thank you. This daemon gave the finishing touch to a game
that I made for my family. They LOVED it and we had such a blast
watching them play the game. Thank you again so much and happy
holidays!