[I6] How do I handle images in a dark room?

I am just testing my current game and suddenly realised that I’ve got a problem with a dark room. The game is written using Inform 6, has images for every room and is compiled to run with a Glulx interpreter. I am currently drawing the images in the room’s description property. Some of the images are conditional.

The problem is that one of the rooms is dark. I need to provide a dark image when the room is dark (which I had forgotten about). Unfortunately, the routine in the description property is never executed when the room is dark, as the player is not actually in that location, but in thedark. Is it possible to change the description for thedark to a routine where I can draw the dark image?

2 Likes

Have you tried to change the properties of thedark object?

Object  thedark "(darkness object)"
  with  initial 0,
        short_name DARKNESS__TX,
        description [;  return L__M(##Miscellany, 17); ];

DM4:

“The designer can ‘‘customise’’ the darkness in a game by altering its ini-
tial, description or short_name properties.”

2 Likes

Thanks. I can probably change (#Miscellany, 17) so that it uses a routine, rather than a string. I’ll give that a try. I did something similar in another game once before (not for graphics, though). I’ve just got to remember how to do it. This isn’t covered in DM4.

Brilliant. That worked. It’s 1:40 a.m. here, so I’ll test it properly tomorrow. Here’s what I used (placed between Include "parser"; and Include "verblib";):

Object LibraryMessages
with
  before
  [;
    Miscellany:
      if (lm_n == 17)
      {
        current_pic = dark_pic;
        DrawGraphics();
        "You can't see a thing. The sunlight shines through the entrance to the west.";
      }
  ];

I’ve only got one dark room. I’d make the message more generic if there were more dark rooms. Needless to say, the two lines before the string are my own graphics handling.

1 Like

You can use LibraryMessages, but also, it seems, make your own routine:

[ InTheDark;
   current_pic = dark_pic;
   DrawGraphics();
   "You can't see a thing. The sunlight shines through the entrance to the west.";
];
[ Initialise;
   thedark.description = InTheDark;   
];

And you can check “real_location” to find out where you really are (and not “location” which is equal to ‘thedark’).

Sweet dreams.

2 Likes

Thanks @auraes. It’s always good to go to bed knowing that you’ve just solved a problem, otherwise you can’t get to sleep while worrying about it.

I actually tried your second solution and it failed because I had thedark.description = InTheDark(); Note the brackets. This obviously didn’t work because it was calling the routine and giving some sort of programming error. After all these years, I didn’t know that you could allocate a routine to a property like that. I’ll have to add that to my list of Inform 6 tricks.

1 Like

There is another problem. When you turn the lamp on in the dark room, the room is redescribed, so the image is updated. However, when you turn the lamp off, the short_name is changed, but the description isn’t, so you have to force the image to be updated when changing from light to dark. I did it in a before rule, like this:

    SwitchOff:
      if (self hasnt light)
        "It's already off.";
      give self ~light;
      if (~~OffersLight(location))
      {
        current_pic = dark_pic;
        DrawGraphics();
      }
      "The lamp goes out.";

I just thought I’d just mention this in case anyone else finds it useful. If there’s anything I haven’t thought of, feel free to add it here.

in David Griffith’s changelog you’ll find something like this:

NewRoom() is called on light-to-light and dark-to-light;
DarkToDark() is called on dark-to-dark;
thedark.initial() is called on light-to-dark.

[ InTheDark;
   current_pic = dark_pic;
   DrawGraphics();
];
[ Initialise;
   thedark.description =  "You can't see a thing. The sunlight shines through the entrance to the west.";
   thedark.initial = InTheDark;  
];

I didn’t test it thoroughly.

Alternatively, instead of if (~~OffersLight(location)) you can try if(location == thedark).

The stuff you mentioned in the changelog only applies when you move from room to room, not when the state of light changes when you haven’t moved anywhere.

I tried the test for if (location == thedark) and that didn’t work because the location hadn’t yet been updated at the point where the test needs to be done, hence the use of OffersLight(location), as this forces a re-evaluation of light.

You see, there is method in my madness.

It works for me. You must have put your SwitchOn and SwitchOff in a Before instead of an After.

1 Like

You’re right. I’ve got it in a before, rather than an after, as there are other things that need to be tested before the action can take place. My lamp isn’t like a flashlight.

Yes, but now the images don’t show up if I go from darkness to light in the same room. Forget it.

Yes, it’s quite tricky to get it right. I’ll be sending it to you to test the full game within the next day. I’m just giving it some last-minute tweaks.