Discussion:
Inform 7 lamps
(too old to reply)
Clay Hobbs
2009-10-27 20:42:50 UTC
Permalink
I'm currently working on my first IF, and I want it to have a
flashlight that can be either on or off. I figure that it would be
easiest to make this a kind for other games, but I'm having some
trouble. After much trying and failing with various things added to
the following:

A lamp is a kind of device. A lamp is either on or off. A lamp is
usually off.

I still have nothing useful. I think my trouble was with setting the
lamp lit or unlit when it is turned on or off. I searched around and
couldn't find any extensions on the Inform 7 site that seemed to have
what I wanted. Please help, I don't know what to do here.
Al
2009-10-27 21:00:04 UTC
Permalink
I still have nothing useful.  I think my trouble was with setting the
lamp lit or unlit when it is turned on or off.  I searched around and
couldn't find any extensions on the Inform 7 site that seemed to have
what I wanted.  Please help, I don't know what to do here.
the following is just a rough implementation to get you started:

"Game" by the Author

Starter is a room.

a device called a lamp is in starter.

a thing can be either on or off.
a thing is usually off.


instead of switching on the lamp:
now the lamp is lit;
now the lamp is on;
say "You turn on the lamp.".

instead of switching off the lamp:
now the lamp is unlit;
now the lamp is off;
say "You switch off the lamp.".
Mike Tarbert
2009-10-27 21:09:04 UTC
Permalink
Post by Clay Hobbs
I'm currently working on my first IF, and I want it to have a
flashlight that can be either on or off. I figure that it would be
easiest to make this a kind for other games, but I'm having some
trouble. After much trying and failing with various things added to
A lamp is a kind of device. A lamp is either on or off. A lamp is
usually off.
I still have nothing useful. I think my trouble was with setting the
lamp lit or unlit when it is turned on or off. I searched around and
couldn't find any extensions on the Inform 7 site that seemed to have
what I wanted. Please help, I don't know what to do here.
The built - in property for devices in inform is "switched on / switched
off" -- not "on / off." Making a lamp a kind of device is all you need
to give it the either / or property "switched on / switched off." Note
that you don't *have* to make it a kind of device for this to work; you
can also just make it a kind of thing and give it that property manually
by saying "A lamp can be switched on or switched off."

This will allow you to turn the lamp on or off using a variety of syntax
which can be looked up in the actions index under the actions "switching
on" and "switching off." It also automatically provides checks so that,
for example, trying to turn something on that is already on gets a
refusal message ("That's already on"). What it doesn't do is provide any
actual consequences to turning the device on (other than changing the
property to "switched on"). You need to add this yourself in
(preferably) a carry out rule:

[code]
A lamp is a kind of device.

Carry out switching on a lamp:
now the noun is lit.

Carry out switching off a lamp:
now the noun is unlit.

The lab is a room. It is dark. "This is your lab." The player carries a
lamp called the brass lantern.

test me with "turn on lantern / switch on lantern / turn it off / l /
turn lantern off / turn it on / l / i".
[/code]
Jim Aikin
2009-10-27 22:27:21 UTC
Permalink
Post by Clay Hobbs
A lamp is a kind of device. A lamp is either on or off. A lamp is
usually off.
Also note that you don't need to (and shouldn't) make it a _kind_ of
device unless you're planning to have a number of lamps in the game, all
of which use some of the same functionality. The phrase "kind of" has a
specific meaning in Inform, it's not just a friendly English phrase. If
you only need one lamp, just write:

The old brass lamp is a device.

Now, a "device" in Inform is assumed to have a switch. So if the lamp is
meant to be lighted with a match, or by rubbing it, making it a device
is probably a bad idea. As Mike said, just make it a thing.

Here's a basic implementation, which takes advantage of the fact that
Inform has a built-in property, "lit", which will cause the lamp to give
off light, thus illuminating dark rooms. What the code below doesn't do
is handle the question of how exactly the lamp would be lit.

[code]
The player carries the old brass lamp. The lamp can be lit. The
description of the lamp is "[if lit]The lamp is glowing
brightly[otherwise]The lamp is dark[end if]."

Instead of burning the lamp:
if the lamp is lit:
say "The lamp is already lighted.";
otherwise:
now the lamp is lit;
say "You light the lamp."

Instead of switching on the lamp:
if the lamp is lit:
say "The lamp is already lighted.";
otherwise:
say "There doesn't seem to be a switch."

Extinguishing is an action applying to one thing and requiring light.
Understand "extinguish [something]" and "unlight [something]" and "put
out [something]" as extinguishing.

Check extinguishing:
if the noun is not the lamp:
say "You can't extinguish [the noun], as it isn't on fire." instead;
otherwise if the lamp is not lit:
say "The lamp is not lit, so it doesn't need to be extinguished." instead.

Carry out extinguishing:
now the lamp is not lit.

Report extinguishing:
say "You put out the lamp."
[end code]

--JA
Clay Hobbs
2009-10-28 00:42:31 UTC
Permalink
Thank you everyone, now my game has a functioning flashlight! And
yes, I was going to have multiple ones in the game (I'm planning on
having things like falling down a trap door and your flashlight breaks
because you land on it, then you get a new one somewhere). I'll
probably add more functionality, like broken lamps and fuel. Thanks
again for the help!
weevil
2009-10-31 05:45:55 UTC
Permalink
On this tangent, has anyone turned the light switch example in the
inform documentation into a kind so that I can just drop 'there is a
lightswitch in the room' for each room I want lights in? I started to
do it myself but I got tripped up when it came to including the
'carry out' statements in a generic, rather than specific way.
Mike C
2009-10-31 11:53:40 UTC
Permalink
Post by weevil
On this tangent, has anyone turned the light switch example in the
inform documentation into a kind so that I can just drop 'there is a
lightswitch in the room' for each room I want lights in? I started to
do it myself but I got tripped up  when it came to including the
'carry out' statements in a generic, rather than specific way.
I have not looked at this in detail, but one way of doing this would
be to set up a relation between light switches and lights. A partial
implementation would be:

<code>
A lightswitch is a kind of device. A lightswitch is usually switched
off. The plural of lightswitch is lightswitches.
A lamp is a kind of thing. A lamp is usually unlit.

Connecting relates various lamps to one lightswitch.

The verb to be connected to implies the connecting relation.

The Study is a dark room. The desklamp is a lamp in the Study. The
rocker switch is a lightswitch in the study. The desklamp is
connected to the rocker switch.

carry out switching on a lightswitch:
if the lightswitch is switched on:
say "The [noun] is already switched on." instead;
otherwise:
now the noun is switched on;
now everything connected to the noun is lit;

After deciding the scope of the player when in darkness:
repeat with N running through lightswitches in the location:
place N in scope.
<code>

This is simply to show how the relationship is set up. It does not
implement switching off or deal with someone trying to switch on the
lamp directly. Additional reporting rules would be required. Also,
you would need to deal with situations where someone wants to turn on
the lamp directly, not using the switch, perhaps by diverting the
switching on action to the switch connected to the relevant lamp, etc.
M***@mailinator.com
2009-10-31 18:04:39 UTC
Permalink
Post by weevil
On this tangent, has anyone turned the light switch example in the
inform documentation into a kind so that I can just drop 'there is a
lightswitch in the room' for each room I want lights in? I started to
do it myself but I got tripped up  when it came to including the
'carry out' statements in a generic, rather than specific way.
"Down Below"

A light switch is a kind of device.
A light switch is always fixed in place.
A light switch is usually switched on.

Carry out switching off a light switch: now the location of the noun
is dark.
Carry out switching on a light switch: now the location of the noun is
lighted.

Understand "flip [something switched off]" as switching on. Understand
"flip [something switched on]" as switching off. Understand "flip
[something]" as switching on.

After deciding the scope of the player:
let s be a random light switch in the location;
if s is a light switch, place s in scope.

Terrifying Basement is a room. There is a light switch in the
basement. Upstairs is above the Terrifying Basement.
Creepy Closet is east of Upstairs. There is a light switch in the
closet.

Test me with "turn off light / look / flip light switch / up / east /
flip switch".
weevil
2009-10-31 18:13:17 UTC
Permalink
Aha! "now the location of the noun"! I was so close and yet so far....
Post by M***@mailinator.com
Post by weevil
On this tangent, has anyone turned the light switch example in the
inform documentation into a kind so that I can just drop 'there is a
lightswitch in the room' for each room I want lights in? I started to
do it myself but I got tripped up  when it came to including the
'carry out' statements in a generic, rather than specific way.
"Down Below"
A light switch is a kind of device.
A light switch is always fixed in place.
A light switch is usually switched on.
Carry out switching off a light switch: now the location of the noun
is dark.
Carry out switching on a light switch: now the location of the noun is
lighted.
Kostas Diamandopoulos
2009-11-08 13:34:58 UTC
Permalink
Hello, I am new to "Inform 7", and I'm trying to make my first game,
but I have a problem. The first thing I want the player to do in the
game is "Turn light on", to lit the room. As simple as that, but I
don't know how to do it. The light is fixed to the specific room.

I tried using this:

Light is a kind of device.

Carry out switching on Light:
now the noun is lit.

Carry out switching off Light:
now the noun is unlit.

The Bedroom is a room. The bedroom is dark. A Light called lights is
in the bedroom.

test me with "turn on light / switch on light / turn it off / l /
turn light off / turn it on / l / i".



But it gives me this:

Darkness
It is pitch dark, and you can't see a thing.
turn light on
You can't see any such thing.
turn on light
You can't see any such thing.
Erik Temple
2009-11-08 15:10:15 UTC
Permalink
On Sun, 08 Nov 2009 07:34:58 -0600, Kostas Diamandopoulos
Post by Kostas Diamandopoulos
Darkness
It is pitch dark, and you can't see a thing.
turn light on
You can't see any such thing.
turn on light
You can't see any such thing.
You get this because of the way Inform's concept of darkness works. When a
room is dark in Inform, nothing in it can be seen by the player, meaning
that the player can't see it to interact with it in the first place. What
you need to do is make the lights an exception to this rule:

<code>

A light is a kind of device. It is fixed in place.

Carry out switching on a light:
now the noun is lit.

Carry out switching off a light:
now the noun is unlit.

The Bedroom is a room. The bedroom is dark. A light called the
light-switch is
in the bedroom. Understand "lights" as light-switch.

After deciding the scope of the player while in the bedroom:
place the light-switch in scope.

test me with "turn on light / switch on light / turn it off / l /
turn light off / turn it on / l / i".

</code>

Every turn, Inform looks at all the objects to determine what is visible
to the player. All of these objects are considered to be "in scope". The
"after deciding the scope of the player" line above tell Inform that,
after it has automatically decided what should be in scope, we want to add
an exception, in this case for the light-switch.

You'll notice that I changed the name of your object from "lights" to
"light-switch" to avoid a naming conflict with the kind "light". As the
code was originally written, Inform would have understood "lights" as
referring to the kind (since it automatically understands plurals).

--Erik
John Gottschalk
2009-11-20 15:01:55 UTC
Permalink
Do you know how to implement in various levels of lighting?
So instead of having to put multiple things in scope when the room is
dark, You can have dark, dim light and bright light.
Then have some way of making things visible in dim light or in bright
light, and some things only in bright light.

John
Mike Tarbert
2009-11-20 16:27:03 UTC
Permalink
Post by John Gottschalk
Do you know how to implement in various levels of lighting?
So instead of having to put multiple things in scope when the room is
dark, You can have dark, dim light and bright light.
Then have some way of making things visible in dim light or in bright
light, and some things only in bright light.
John
See the Recipe Book, ch.3.7. -- Lighting, specifically example 327 --
"Zorn of Zorna."

Skinny Mike

Loading...