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.
> 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.".
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]
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
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.
"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".
On Oct 31, 1:04 pm, "M8R-dn7...@mailinator.com" <M8R-
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.
> 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
See the Recipe Book, ch.3.7. -- Lighting, specifically example 327 --
"Zorn of Zorna."
Skinny Mike