Can I write a routine which checks if I wear clothes or do I have to check it in every room?
This is the simple routine I want to check everywhere:
[ Naked;
if (hiking_clothes hasnt worn){
print
"^You're freezing because you're no longer wearing your hiking clothes. Really not a good idea!^";
TakeDamage(2);}];
Thank you for the advice. I added the rooms where the clothes are not needed and now it works fine;=)
[ Naked;
if
((hiking_clothes hasnt worn) &&
(location ~= ShoreLake) &&
(location ~= InsideLake) &&
(location ~= Underwater) &&
(location ~= Oasis)){
print
"^You feel unprepared without your sturdy hiking clothes. The terrain ahead looks challenging, and the thought of tackling it
without proper gear makes you hesitate. The cold wind bites at your exposed skin, and every step feels like a reminder that you
should dress appropriately for the journey.^";
TakeDamage(1);}];
The solutions given will work, but they’re very wasteful, as the daemon is running all the time and the daemon is doing a lot of checks on every turn.
I would attack this differently as follows:
Add the following global attribute somewhere after including globals.h:
Attribute cold;
Add this attribute to each room that is cold, such as:
has cold light;
Define your clothes something like this:
Object clothes "clothes" room01
with
article "your",
name 'sturdy' 'hiking' 'clothes',
description "They're your sturdy hiking clothes.",
after
[;
Disrobe:
StartDaemon(self);
Wear:
self.time_left = 5;
StopDaemon(self);
],
daemon
[;
if (location hasnt cold)
{
self.time_left = 5; !Optionally, reset the timer
return;
}
self.time_left--;
if (self.time_left > 2)
"^The cold wind bites at your exposed skin. Every step feels like a reminder that you should dress appropriately for the journey.";
if (self.time_left > 0)
"^You'd better wear something to protect you from the cold..and quick.";
deadflag = 1;
"^You freeze to death.";
],
time_left 0,
has clothing pluralname;
If your clothes aren’t worn at the start of the game, start the daemon in Initialise:
[ Initialise;
StartDaemon(clothes);
];
In this way, all the code is localised in the clothes (as it should be), it only runs when the clothes are not worn and it returns as quickly as possible if the room is not cold. You can do whatever you like when the room is cold. The above code is just an (untested) example.
EDIT: @fredrik pointed out that I had StartDaemon() and StopDaemon() the wrong way around. Now corrected. The daemon should be running when you’re not wearing your clothes, so I’ve also added step 4. I hope I’ve got it right, this time.