Check for worn clothes in every room

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);}];

Thanks and a nice weekend!

In Initialise do this:

player.daemon = Naked;
StartDaemon(player);

You could also use the each_turn property, since the player object will always be in scope.

You can attach your routine to the each_turn property of selfobj as part of your Initialise() routine, as with:

[ Initialise ;

	location = Start;	! or whatever room name
	selfobj.each_turn = Naked;

];

The approach suggested by fredrik has the advantage that you can easily turn it off by stopping the daemon.

1 Like

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);}];

Thanks a lot!

Check the post on discord.
Make a class for the rooms you don’t need the hiking gear for and just make a simple rule:

if (location ofclass Classname) “You are naked but comfortable”;
else “You freeze to death”;

(Example reversed on Discord)

1 Like

You can also compare a value to several values in one go - the Inform code gets shorter and easier to read AND the compiled code gets more efficient:

if(hiking_clothes hasnt worn && 
    location ~= ShoreLake or InsideLake or Underwater or Oasis)
 ...
2 Likes

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:

  1. Add the following global attribute somewhere after including globals.h:
Attribute cold;
  1. Add this attribute to each room that is cold, such as:
has cold light;
  1. 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;
  1. 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.

2 Likes