Page 1 of 1

Smoke Detectors

Posted: Fri Sep 14, 2012 1:24 pm
by Tdarcos
I have realized I have been violating the law by having rooms with no smoke detectors. But, since it's just a game I only really need one. Is there a way I can have a room move the smoke detector to it before the room's contents are listed, or in the alternative, put a check so that if the player moves to a room with a certain attribute, to move the smoke detector there?

Re: Smoke Detectors

Posted: Fri Sep 14, 2012 1:26 pm
by Tdarcos
Sorry, I forgot to add, I used a before routine for object MovePlayer for a room, and it didn't work.

Posted: Fri Sep 14, 2012 2:31 pm
by pinback
Isn't there some "found_in" attribute you can use for that? I forget if that's Hugo or Inform 6.

Posted: Fri Sep 14, 2012 2:49 pm
by Roody_Yogurt
Yeah, Hugo has a "found_in" property. That's one way to go.

Tdarcos, MovePlayer didn't work for you since using the before property, in that case, only works for the room you are moving *from*. In this case, you'd want to use the after property.

If every room has access to the smoke detector, you could give it the in_scope property:

Code: Select all

in_scope <player_object>
That'd mean it's always within view of the player. You could also throw your attribute check in there, like:

Code: Select all

in_scope
     &#123;
     if location is smokesafe
          return <player_object>
     else &#58; return 0
     &#125;
Or to use "found_in" like pinback suggested:

Code: Select all

found_in
     &#123;
     if location is smokesafe
         return location
     else &#58; return 0
     &#125;
Here's an example of doing an after check for MovePlayer. We'll put the code into the player object (otherwise, we'd probably want to make a class for all of the rooms with smoke detectors and throw the code in there):

Code: Select all

player_character you "you"
&#123;
after
    &#123;
    actor MovePlayer
        &#123;
        if location is smokesafe
             move smoke_detector to location
        &#125;
     &#125;
&#125;
&#125;

Posted: Fri Sep 14, 2012 3:24 pm
by Tdarcos
Roody_Yogurt wrote:Yeah, Hugo has a "found_in" property. That's one way to go.

Code: Select all

player_character you "you"
&#123;
after
    &#123;
    actor MovePlayer
        &#123;
        if location is smokesafe
             move smoke_detector to location
        &#125;
     &#125;
&#125;
&#125;
Both Pinback's suggestion of found_in and your actor suggestion both work to put the smoke detector in the room, but in both cases, it's not showing up in the list of items in the room.

However, thanks to your explanation I figured out how to do it:

Code: Select all

player_character you "you"
&#123;
before
    &#123;
		actor MovePlayer
        &#123;
			if object is smokesafe
				move smoke_detector to object
			return false
        &#125;
	&#125;
&#125;
I did a test where instead of the if statement, I had it print location.name, object.name and xobject.name. Location is still the room being left. Object in this case is the destination room, which is what I want.

The "return false" is required or it presumes the move was not to happen. The item silently moves if necessary, and the move takes place and the item is there, and lists in the list of things in the room. Slick.

Thanks.

Posted: Fri Sep 14, 2012 3:26 pm
by Tdarcos
Oh sorry, I forgot, obviously the smoke detector does not use "found_in" with this changed method, I set "in" to the initial room where the smoke detector is, and it works okay and is visible.

Posted: Fri Sep 14, 2012 3:54 pm
by Roody_Yogurt
Yeah, found_in and in_scope items are not technically in whatever room, so they are not listed (but they are accessible). I was unclear that was one of the criteria we were shooting for.

The after MovePlayer method's problem was that DescribePlace is called before the after routines are checked. If you typed >LOOK again, I'm sure it'd show up, but yeah, for your purposes, looks like you found the right solution.

Posted: Fri Sep 14, 2012 6:19 pm
by Gerynar
I thought found_in was used more like this:

Code: Select all



object smoke_det
&#123;
	found_in STARTLOCATION, hall, another_room ! thee holding cells for locations
	long_desc &#123;
		"Small, round and slightly radioactive, the smoke detector stands a
		lonely vigil against the evils of fire and smoke."
	&#125;
	noun "detector"
	adjectives "smoke", "small", "round", "white", "radioactive", "slightly"
&#125;

room STARTLOCATION "Start Location"
&#123;
	long_desc &#123;
		"This is just a blah room. "
		if FindObject&#40;smoke_det, location&#41;
			call &#40;&smoke_det.long_desc&#41;
		else
			"Better not start any fires in here."
	&#125;	
	n_to another_room
&#125;

room another_room "Another room"
&#123;
	long_desc &#123;
		"This is just another room, somewhat kitchenesque in looks. ";
		if FindObject&#40;smoke_det, location&#41;
			"It seems to be safe to actually cook food in here as there is a
			smoke detector here."
		else
			"Who in their right mind would have a kitchen without a smoke detector!"
	&#125;
	
	s_to STARTLOCATION
	n_to hall
&#125;

room hall "long hall"
&#123;
	long_desc &#123;
		"This is a rather long, lonely looking hall. ";
		if FindObject&#40;smoke_det, location&#41;
			"The smoke detector comfortably stands vigil on the ceiling of the
			hall."
		else
			"Bad place to get caught in a fire."
	&#125;
	
	s_to another_room
	
	after
	&#123;
		location DoGo
		&#123;
			smoke_det.found_in #3 = 0
		&#125;
	&#125;
&#125;
note: Add this code after the player_character in the shell file to try it out. Note the use of FindObject() code in the three rooms, and calling the smoke_det's found_in.long_desc routine to print a standard description of the smoke detector.

This seems to avoid having to move the smoke detector object around.

Also note the after routine in the hall room that "removes" the smoke detector from another_room (third item listed in the found_in property.

Posted: Fri Sep 14, 2012 8:40 pm
by Tdarcos
Roody_Yogurt wrote:The after MovePlayer method's problem was that DescribePlace is called before the after routines are checked. If you typed >LOOK again, I'm sure it'd show up, but yeah, for your purposes, looks like you found the right solution.
Well, the "real" problem was that an entry for moveplayer in the player in a before or after routine is classified as "actor" not as "object". Object is used for everything else because, well, they're objects but when it was in a character, then it's an actor, which is why it wasn't working because I called it object.

Posted: Fri Sep 14, 2012 8:57 pm
by Tdarcos
Gerynar wrote: This seems to avoid having to move the smoke detector object around.
For what I'm doing, moving the smoke detector is a lot simpler because, all I have to do is add the (Thanks Roody, for the name!) SmokeSafe attribute to any room that I want the detector in, and it shows up. The 4 lines in the player character to see if the room is smokesafe and to move if true, plus one attribute on any room it's to be in. Much simpler than doing lots more code in the long_desc of every room.

I kind of thought of that, initially, when Pinback suggested the found_in property, except that adding the smoke detector mention in long_desc does not look the same as when the room description routine (when entering the room for the first time or with the LOOK command).

Besides, it's just a gimmick. All the smoke detector does is if you push it (or push the test button attached to it) is say that it beeps, indicating it's working.

I happened to have the Public Service Channel on the cable on in the background while I was working on the game, and it mentioned how too many places - as many as half of all homes, despite the fact your local fire station will give you a smoke detector for free - don't have smoke detectors and a lot of people - especially children - die of smoke inhalation or are burned to death because they don't get that extra few minutes of warning telling them that there's a smoke danger.

Then I got thinking, why not put one in? Then I wanted something more elegant, instead of one detector in each room adding 30 or 40 identical smoke detectors, just have one that follows the user around to the various indoor rooms that have one. And it's nice, the rooms outside don't have it (they're not "smokesafe") and neither does the bathroom. (Exactly what's going to burn in a bathroom?)

I already did something like this in the building, it has a large air conditioner on the roof, which can only be shut off from the breaker in the <s>fuse box</s> breaker box, and then if you turn the A/C off, every room in the house without windows gives a complaint when you enter it that it's stuffy and you need to turn the A/C back on. Then once you turn it back on, it is noticably cooler.

Oh yeah, I think I'll put a fire extinguisher in the kitchen.

Posted: Fri Sep 14, 2012 10:03 pm
by Roody_Yogurt
You know, Paul, back when this place was fairly new, Ben was working on his own Hugo game. It also involved plumbing and fire and, more importantly, explode-y things. That game was called "Burning Down the House." You can read about it here:

http://www.joltcountry.com/phpBB2/viewtopic.php?t=16
http://www.joltcountry.com/phpBB2/viewtopic.php?t=19
http://www.joltcountry.com/phpBB2/viewtopic.php?t=31
http://www.joltcountry.com/phpBB2/viewtopic.php?t=158

Ben gave up on this dream long ago, but maybe it's time you gave it new life. Could your game have an exploding stove? A toilet bowl that you can empty? The possibilities are endless!