A light problem with The Librarian

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 7676
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

A light problem with The Librarian

Post by Tdarcos »

I decided to get back into programming to give me a break from time-to-time when writing my book Marnie. So I have resumed work on The Librarian, and in the process of doing so, I have encountered a light problem.

Background
You - the player - wake up in your bed after too much partying. The narrator recommends you GET UP and take care of the usual things you would do. So, you're going to go into the bathroom, to shower, perhaps use the toilet, brush teeth, shave, etc. But the room is dark, so you need to turn on the light. Only it doesn't work. That's not part of the game.

First, I present various parts of the code. I replaced Darkwarning because where there is a light switch, it would tell them to turn it on. In the game, where text appears IN UPPER CASE it's a hint to the player this is a recommended command. But where I expect the room to become visible, it does not.

Here is the relevant code:

Code: Select all

room your_bathroom "Bathroom"
{
    sw_to your_corridor
    out_to your_corridor
    w_to your_room
    in_to your_room
    long_desc
      "You are in your bathroom. You
      can GO SW or OUT to
      the hallway, GO IN or WEST to
      your room."
    is private , not light
}

lightswitch switch01
{
  in your_bathroom
}

class lightswitch  "light switch"
{
  type lightswitch
  nouns "light", "switch"
  adjective "a"
  is static, switchable, not switchedon, powered
  breaker_num 200 ! no specific breaker

  after
    {
      object DoSwitchOn, DoSwitchoff
        {
          local PP
          PP = Parent(Player)
          "Obj is ";
          if object is not switchedon
             "not ";
          print "switched on. PP("; number pp; ")="; pp.name; \
             " Loc("; number location; ")="; location.name

             if location is not light
                "(bef) location is not light"
             else
                "(bef) location is light"

          if location is not light
             location is light
          else
             location is not light

         if location is not light
                "(aft) location is not light"
          else
                "(aft) location is light"

          DoLookAround
        }
    }
}

replace DarkWarning
{
! 2020-06-01 PR Check if there's a light switch in here
  local i,pp

  pp = Parent(Player)
  for i in pp
  {
    if i.type = lightswitch
    {
      print "It's pitch black in here. "; \
        CThe(player); " need"; MatchSubject(player); \
  		  " to TURN ON LIGHT."
      return
    }
  }
	print CThe(player); " stumble"; MatchSubject(player); \
		" around in the dark."
}



The extra message display is so I can see what is happening.

This is what happens when the game is played (transcript shortened for brevity):


Good evening, it is 9:41:52 p.m., on Monday, June 1, 2020.
Hello and welcome. Your objective is to get a book from the public library, any one in the region. [deleted]

The Librarian
A story of books (books? What are books?) And their acquisition.
[deleted]

Your room, lying on the bed
You awaken in your bed after a night of activities [deleted]
Anyway, since you're awake and not hung over, it probably wouldn't be a bad idea to GET UP and out of bed, and start the routine tasks you have to do when you first get up in the morning.

>get up
You have gotten out of bed and are standing in the middle of the room.

>look

Your room
This is your room'. From here, you can GO IN or EAST to the bathroom, .
The bed is here.

>east
It's pitch black in here. You need to TURN ON LIGHT.

>turn on light
Obj is switched on. PP(117)=Bathroom Loc(117)=Bathroom
(bef) location is not light
(aft) location is light
It's too dark to see anything.

>look
It's too dark to see anything.

>turn on light
Light switch's already turned on.

>turn off light
Obj is not switched on. PP(117)=Bathroom Loc(117)=Bathroom
(bef) location is light
(aft) location is not light
It's too dark to see anything.

>west

Your room
This is your room'. From here, you can GO IN or EAST to the bathroom, .
The bed is here.

>east
It's pitch black in here. You need to TURN ON LIGHT.

>turn on light
Obj is switched on. PP(117)=Bathroom Loc(117)=Bathroom
(bef) location is not light
(aft) location is light
It's too dark to see anything.

>w

Your room
This is your room'. From here, you can GO IN or EAST to the bathroom, .
The bed is here.

>e

Bathroom
You are in your bathroom. You can GO SW or OUT to the hallway, GO IN or WEST to your room.
Toilet, shower, sink, and light switch are here.

>
[/size]
So the thing is that if the bathroom is exited with the light on then re-entered, it works, but turning the light on and staying in the room does not work.

If you need more details, please ask. Thank you.
"You're motorin', what's your price for flight, when finding Mr. Right?"
- Night Ranger, Sister Christian

User avatar
Tdarcos
Posts: 7676
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Solution

Post by Tdarcos »

I found the solution to the problem.

On the last line of the After routine, change
DoLookaround
to
MovePlayer(Location)

This reloads the room, either making the room visible if the light was turned on, or returning the message that it is now pitch black.

I'd like to than Paul Robinson for his assistance in solving this problem.
"You're motorin', what's your price for flight, when finding Mr. Right?"
- Night Ranger, Sister Christian

Roody_Yogurt
Posts: 2080
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: A light problem with The Librarian

Post by Roody_Yogurt »

As far as I can tell, the issue was in your own code, right? If it's a problem within the Hugo library or Roodylib, you'll have to explain further.

User avatar
Tdarcos
Posts: 7676
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: A light problem with The Librarian

Post by Tdarcos »

The thing is, I turn the light on, but the system does not recognize it. Nothing happens. I'm thinking of the example of someone carrying a lamp, who turns it on after entering a dark room. Presumably doing this would then light the place up. I hadn't bothered to look at other games like Adventure or Dungeon to see how they solved the problem, maybe they do the same thing.

It just seems strange that if one turns on a light source you have to reenter the room to activate (or deactivate) it.
"You're motorin', what's your price for flight, when finding Mr. Right?"
- Night Ranger, Sister Christian

Roody_Yogurt
Posts: 2080
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: A light problem with The Librarian

Post by Roody_Yogurt »

Does your code call FindLight(location)? Here is some flashlight code from "the vault of hugo".

Code: Select all

		object DoSwitchOn
		{
			"A beam of serviceable light appears from your
			flashlight."
			self is light
			FindLight(location)
			if location is not visited
			{
				DescribePlace(location)
				location is visited
			}
		}

User avatar
Tdarcos
Posts: 7676
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: A light problem with The Librarian

Post by Tdarcos »

Roody_Yogurt wrote: Sat Jun 06, 2020 12:39 pm Does your code call FindLight(location)?
I am practically certain DescribePlace does that, which is why calling it still keeps the old light status.

Oh wait. I see. I wasn't using DescribePlace, I was using DoLookAround, and maybe it does not call FindLight. I might have to check both. And I might try that as an alternative, and possibly your suggestion from your flashlight code.
Roody_Yogurt wrote: Sat Jun 06, 2020 12:39 pm

Code: Select all

			FindLight(location)
			if location is not visited
			{
				DescribePlace(location)
				location is visited
			}
There is one thing about this. When you move into a room, isn't the Visited flag raised anyway? If it's not raised when it's too dark to see, then this will work.

I mean, the solution I gave above does work and I don't think it charges for a second turn. I appreciate your assistance, and where can I find "the vault of hugo"? Is it a publicly accessible resource?

I did find one thing I wasn't expecting when I did a search for it. In Batman - Arkham City the Catwoman bundle pack has her planning to rob The Vault of Hugo Strange.
"You're motorin', what's your price for flight, when finding Mr. Right?"
- Night Ranger, Sister Christian

Roody_Yogurt
Posts: 2080
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: A light problem with The Librarian

Post by Roody_Yogurt »

the vault of hugo is here:

https://www.ifarchive.org/if-archive/pr ... sample.hug

And yeah, rooms aren't given the visited attribute until they have light or else players would never see things like initial_desc if they first visited it while it's dark.

User avatar
Tdarcos
Posts: 7676
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: A light problem with The Librarian

Post by Tdarcos »

Rody, you've been correct on all points.
1. DescribePlace doesn't check for light
2. Visited is not set until the person can see
3. If they can't see, on turning on the light, the light source must set the Visited flag
#3 would provide an interesting "sneak peek" look in a room that the room thinks has never visited it. Or if they keep turning off the light before leaving, could sneak in and get something. This might be useful for burglary scenarios.Th guy sneaks in wearing night vision goggles and an infrared flashlight, whereas if he turned the light on or used a "regular" flashlight it could set off an alarm.

Thank you for all your help.
"You're motorin', what's your price for flight, when finding Mr. Right?"
- Night Ranger, Sister Christian

Roody_Yogurt
Posts: 2080
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: A light problem with The Librarian

Post by Roody_Yogurt »

You're welcome. Good job on living long enough to get it!

Post Reply