Abstracting objects

Hello,

back again with another question. I’m learning Inform 7 and doing pretty well I think, but I am still grokking some concepts of what I can and cannot do.

I know that you can abstract something: A fuse is a kind of thing. fuse1 is a fuse. and in many cases you can use “the item described” to work generical for fuse1 thru fuseN. But I also understand that Inform sometimes needs a concrete object. i.e. fuse1 vs the fuse.

I have 6 sets of fuses sockets, switches and indicators.

As you can imagine, by providing concrete objects all the time, that i have a metric ton of repeated code. This makes bug fixing onerous.

So what i thought I would do would be to create concrete “holders” (fuse0). And what I wanted to do is use a (function?) to process all six sets of options.

The code below compiles, but doesn’t yield what i want to do. The code in question is below the comment: {=========================]

Thanks in advance,
d.

Release along with cover art, a website, an introductory booklet, and an introductory postcard.

Use scoring.
Use American Dialect.
Use serial comma.
The maximum score is 100.
The block giving rule is not listed in the check giving it to rules.

Sound of Bell is the file "StrongmanBell.ogg".

The Swiss Army knife is in the Electrical Room. The Swiss Army knife is an open container. The screwdriver, awl, fingernail clippers, can opener, and corkscrew are in the Swiss Army knife. Understand "screwdriver" as knife. The description of the Swiss army knife is "This is the standard issue Swiss Army knife." 

instead of taking when the noun is in the swiss army knife, say "That[']s part of the Swiss Army knife. You can[']t take that!" instead.

The silver key is in the Electrical Closet One. The description of the silver key is "This is a small silver key. I wonder what it unlocks."

[electrical room]
Electrical Room is a room. "This is the Electrical Room".
Electrical Room is south of the Generator Room. 
Electrical Room is southwest of Electrical Closet One.
Electrical Room is west of Electrical Closet Three.

every turn when the location is the electrical room:
	say "This room is oozing with electromagnetic energy. You can feel your hair stand on end and all your nerves twitching. This feels dangerous! There are exits in all directions."

[electrical closets]
Electrical Closet One is a room northeast of the electrical room. "This is Electrical Closet One. There[']s an electrical panel here and an exit to the south west."
Electrical Closet Three is a room east of the electrical room. "This is Electrical Closet Three. There[']s an electrical panel here and an exit to the west."

[colors]
Color is a kind of value. The colors are aqua, crimson, emerald, gray, indigo, khaki, magenta, and nondescript. 

[fuses]
A fuse is a kind of thing. The plural of fuse is fuses.
A fuse can be lost or found. A fuse is usually lost. 
A fuse has a color. A fuse is usually nondescript. 
A fuse has a number called fuse id. A fuse id is usually 0.
The description of a fuse is "This is a [color] colored electrical fuse." 
The printed name of a fuse is "a [color] colored fuse".

fuse1 is a fuse. fuse1 is in the electrical room. The fuse id of fuse1 is 1. The color of the fuse1 is aqua. Understand "aqua" and "fuse" as fuse1. 
fuse3 is a fuse. fuse3 is in the electrical room. The fuse id of fuse3 is 3. The color of the fuse3 is crimson. Understand "crimson" and "fuse" as fuse3. 

before taking:
	if the noun is a fuse and the second noun is socket1 and the socket1 is filled:
		say "Taken.";
		now the noun is in the player;
		now indicator1 is switched off;
		now switch1 is switched off;
		stop the action;
	if the noun is a fuse and the second noun is socket3 and socket3 is filled:
		say "Taken.";
		now the noun is in the player;
		now indicator3 is switched off;
		now switch3 is switched off;
		stop the action;

[panels]
An electrical panel is a kind of openable lockable container. The plural of electrical panel is electrical panels.
An electrical panel is usually closed. An electrical panel is usually locked. 
An electrical panel is fixed in place. An electrical panel is scenery.
An electrical panel has a color. An electrical panel is usually nondescript.
An electrical panel has a number called a panel id. A panel id is usually 0.
The description of an electrical panel is "Electrical Panel [the panel id] is a standard issue 200 amp electrical panel supplying 220 power throughout the ride. The electrical panel is [if the item described is open]open. Inside the panel you see a switch, a socket, and an indicator light.[otherwise]closed.[end if] [if the item described is locked]There are screws holding it shut.[otherwise]You can see the cover of the panel sitting nearby.[end if]".
The printed name of an electrical panel is "Electrical Panel [the panel id]".

panel1 is an electrical panel. panel1 is in the electrical closet one. The panel id of panel1 is 1. Understand "panel 1" and "panel" as panel1. The color of panel1 is aqua. The swiss army knife unlocks panel1.
panel3 is an electrical panel. panel3 is in the electrical closet three. The panel id of panel3 is 3. Understand "panel 3"and "panel" as panel3. The color of panel3 is crimson. The swiss army knife unlocks panel3.

instead of turning:
	if the item described is a panel1:
		try unlocking the noun with the second noun instead;
	if the item described is a panel3:
		try unlocking the noun with the second noun instead;
	
instead of locking:
	if the item described is panel1:
		continue the action;
	else if the item described is panel3:
		continue the action;
	otherwise:
		say "You can[']t lock that!" instead.

instead of unlocking:
	if the noun is panel1 and the second noun is the swiss army knife:
		say "Using the screwdriver on the Swiss Army knife, you remove the cover to the electrical panel.";
		now panel1 is unlocked;
		stop the action;
	else if the noun is panel3 and the second noun is the swiss army knife:
		say "Using the screwdriver on the Swiss Army knife, you remove the cover to the electrical panel.";
		now panel3 is unlocked;
		stop the action;
	otherwise:
		say "You can't unlock the [noun] with the [second noun]."

[sockets]
Definition: a socket is filled rather than unfilled if a socket contains a fuse.

A socket is a kind of open container. The plural of socket is sockets.
A socket is fixed in place. 
A socket has a color. A socket is usually nondescript. 
A socket has a number called socket id. a socket id is usually 0.
The description of a socket is "Socket [the socket id] is part of electrical panel [the socket id]. A fuse probably goes in here."
The printed name of a socket is "Socket [the socket id]".

socket1 is a socket. socket1 is part of panel1. The socket id of socket1 is 1. Understand "socket 1" and "socket" as socket1. The color of socket1 is aqua.
socket3 is a socket. socket3 is part of panel3. The socket id of socket3 is 3. Understand "socket 3" and "socket" as socket3. The color of socket3 is crimson. 
	
check inserting a fuse into a socket:
	if the socket is filled, say "But Socket [socket id of the second noun] is already full." instead.

check inserting something into a socket:
	if the noun is not a fuse, say "That won[']t fit in the socket." instead.

check inserting the fuse (called the fuse) into the socket (called the socket) when the color of the fuse is the color of the socket:
	say "You hear a satisfying snick as the fuse slides into place.";
	now the fuse is in the socket;
	stop the action.
	
instead of examining a socket (called the socket) when the socket is unfilled, say "Socket [socket id] is empty." instead.

instead of examining a socket (called the socket) when the socket is filled, say "Socket [socket id] contains [list of things in the noun]." instead.

[switches]
A switch is a kind of device. The plural of switch is switches.
A switch is fixed in place. 
A switch has a color. A switch is usually nondescript.
A switch has a number called switch id. a switch id is usually 0.
A switch has a truth state called points awarded. points awarded is usually false.
The description of a switch is "Switch [switch id] is part of electrical panel [the switch id]."
The description is "Switch [switch id] is part of Electrical Panel [switch id]. It[']s a big switch. You could probably turn it [if the item described is switched off]on[otherwise]off[end if] if you wanted to."
The printed name of a switch is "Switch [the switch id]"

switch1 is a switch. switch1 is part of panel1. The switch id of switch1 is 1. Understand "switch 1" and "switch" as switch1. The color of switch1 is aqua.
switch3 is a switch. switch3 is part of panel3. The switch id of switch3 is 3. Understand "switch 3" and "switch" as switch3. The color of switch3 is crimson.

[indicators lights]
An indicator is a kind of device. The plural of indicator is indicator.
An indicator is usually switched off.
An indicator is fixed in place.
An indicator has a color. An indicator is usually nondescript.
An indicator has a number called an indicator id. an indicator id is usually 0.
The description of an indicator is "Indicator [the indicator id] [if the item described is switched on]is glowing [color of the item described] and [end if]is currently [if the indicator is switched on]indicating something[otherwise]indicating nothing[end if]."
The printed name of an indicator is "Indicator [the indicator id]". 

indicator1 is an indicator. indicator1 is part of panel1. The indicator id of indicator1 is 1. Understand "indicator 1" and "indicator" as indicator1. The color of indicator1 is aqua.
indicator3 is an indicator. indicator3 is part of panel3. The indicator id of indicator3 is 3. Understand "indicator 3" and "indicator" as indicator3. The color of indicator3 is crimson.

Instead of switching on an indicator, say "You can[']t turn that on." instead.

[=============================================================]
switch0 is a switch. socket0 is a socket. indicator0 is an indicator. fuse0 is a fuse.
Instead of switching on or pushing switch1:
	let switch0 be switch1;
	let socket0 be socket1;
	let indicator0 be indicator1;
	let fuse0 be fuse1;
	handle the switches.
	
to handle the switches:
	if switch0 is switched off and fuse0 is not in socket0 and socket0 is filled
		begin;
			now indicator0 is switched off;
			say "You push the switch.";
			say "Nothing obvious happens." instead;
		end if;
	if switch0 is switched off and the fuse0 is in socket0 and the points awarded of switch0 is false
		begin;
			say "The indicator light goes on.";
			now switch0 is switched on;
			now indicator0 is switched on;
			play the sound of Bell;
			increase score by 5;
			now points awarded of switch0 is true;
			stop the action;
		end if;
	if switch0 is switched off and  fuse0 is in socket0 and the points awarded of switch0 is true
		begin;
			say "The indicator light goes on.";
			now switch0 is switched on;
			now indicator0 is switched on;
			stop the action;
		end if;
	if switch0 is switched off and socket0 is filled
		begin;
			now switch0 is switched on;
			now indicator0 is switched off;
			stop the action;
		end if;
	if switch0 is switched on
		begin;
			say "The indicator light goes off.";
			now switch0 is switched off;
			now indicator0 is switched off;
			stop the action;
		end if;

Could you create a snippet of just the relevant parts of the code (so your holders, one set of the needed items, the action code) in a way that would compile?

I can compile it if I just delete the two sound effects lines. Oh, and I cut the first line (Release along with cover art, a website, an introductory booklet, and an introductory postcard.
)

-Wade

That said, @Dana, what would help testers is a test command that runs through the actions to get us to the problem part and demonstrate what’s happening. Especially because you have unimplemented exits and such.

That is, you can include a command like

Test me with "ne/get key/x panel". … etc., just listing all the commands required to automate the demonstration, including showing attempts at the thing that doesn’t work how you want so we can see the responses.

Then we can drop your code in Inform, compile, type ‘test me’ and watch the results.

-Wade

1 Like

The test me is:

Test me with “get knife, aqua, crimson / ne / unlock panel with knife / open panel / put aqua in socket / push switch”

the game should reply with “The indicator light comes on” with a score bump and not “Nothing obvious happens”.

1 Like

I think that what you’re missing is that the syntax for creating a global variable is different from the syntax for creating a new object. You might try:

switch0 is a switch that varies. socket0 is a socket that varies. indicator0 is an indicator that varies. fuse0 is a fuse that varies.

instead of your current code, which is creating off-stage objects switch0, socket0, indicator0 and fuse0.

That said, I think what would really make you happy would be learning some more advanced features, because a lot of what you’re doing in your code is low-level stuff that Inform is designed to do much more easily.

Are you interested in that, or is the above enough for your current purposes?

1 Like

i’m definitely interested in that. This was an effort in providing efficiency over what i was doing before this.

please point me in the right direction. and thank you for the solution!

thanks in advance,
d.

A few things I can see:

Using parts of things instead of a container for the Swiss Army knife:

The Swiss Army knife is in the Electrical Room. The screwdriver, the awl, the fingernail clippers, the can opener, and the corkscrew are parts of the Swiss Army knife.

Your every turn for describing the Electrical Room seems like you’re just making a room description. Just use that whole text for the room description. If that part is dependent on something else (e.g. eventually the electromagnetic energy goes away), you can do something like:

"[if the Electrical Room is electromagnetic]This room is oozing with electromagnetic energy.[else]This is the Electrical Room.[end if] There are exits in all directions."

I’m not entirely sure what the point of the fuse colors are yet (I’m going sequentially through the code) but you don’t have to classify fuse1 with fuse id of 1 and color aqua. You can just say the aqua fuse is a fuse..

Your understand "fuse" as fuse1 and understand "fuse" as fuse3 will cause errors. Instead (I hope this is your intended effect):

Understand "aqua fuse/--" as fuse1. [assuming you don't switch to "aqua fuse" as suggested earlier]

It doesn’t really seem like you’re using IDs?

Your before taking rule with the fuses and sockets can be an instead or (preferably) check...instead.

Probably order your code so that the definitions of indicators, etc. are before their first uses.

Scenery is by definition fixed in place, so defining something as both is redundant.

instead of turning when the noun is an electrical panel:

Your instead of unlocking: code can be a carry out which means you don’t need to stop the action.

You can make a table with all the colors on it if you want, so that instead of assigning individual colors you can just consult the table.

Instead of making a to handle function (which is basically what to ___ rules are), define a new action (handling is an action applying to one visible thing) and use try handling the noun in your instead code.

I’m assuming you have prior programming experience based on your var names and your decision to use begin and end if instead of what Inform calls the colon and indentation syntax. I can see the “traditional” coding influences, but like Otis said there are more efficient ways to do things.

You can nest if statements.

Your repeated code is when you would use a to ___ function:

to switch on the indicator light:
		say "The indicator light goes on.";
		now switch0 is switched on;
		now indicator0 is switched on;

Let me know if you want clarification or have any further questions.

my comments and questions

The reason i made the items “in” the swiss army knife is so that it would list the items. “parts of” do not automagically appear.

In my larger game, the electrical room generates a random move into the electrical closets. when the electromagnetic charge is gone, so will the randomness be.

The reason i have a fuse id and a color property is so that i can compare them to other sockets of the same color as fuses to trigger a “snick”.

“Your understand "fuse" as fuse1 and understand "fuse" as fuse3 will cause errors. Instead (I hope this is your intended effect):” <---- this actually works as intended in the absence of other fuses. my reason for doing this for all the items (fuses, panels, switches, indicators, sockets) is so that in the absence of others (because they’re all in separate rooms) one can refer simply as switch, socket, etc.

Understand “aqua fuse/–” as fuse1. <— what does the “/–” notation mean??

i’m still grokking things but i think i see how a table could help, maybe.

i am a software engineer. (and i find the inform language fascinating in that i can see how compilation works, for the most part.)

Otis’ hint about making my switch0, etc items that vary worked in my first case but i found i couldn’t reassign them after the initial assignment. ← turns out i needed a “now switch0 is switch1” instead of a “let switch0 be switch1”

d.

I agree w/ @Hidnook that this is better implemented as parts.

The screwdriver, the awl, fingernail clippers, the can opener, and the corkscrew are part of the Swiss Army knife. Understand "screwdriver" as the Swiss Army knife.

[I would add the tools to the description, but you'll need to put them somewhere in any case:]

The description of the Swiss army knife is "This is the standard issue Swiss Army knife. It has [a list of things which are part of the item described]."

This might not seem shorter, but it will be in the long run if you have a many more fuses:

Understand "fuse" as a fuse. 
Understand the color property as describing a fuse.
An aqua fuse called fuse1 is in the electrical room. The fuse id of fuse1 is 1.
A crimson fuse called fuse3 is in the electrical room. The fuse id of fuse3 is 3.

In addition to the things that Hidnook and BadParser pointed out…


The Inform compiler is smart enough to figure out most plurals on its own, so you don’t need lines like:

The plural of fuse is fuses.

When you’re setting up a printed name, you don’t need or want the article to be a part of it, so

The printed name of a fuse is "a [color] colored fuse".

can be simplified to

The printed name of a fuse is "[color] colored fuse".

You’ll be able to get the correct article (either “a” or “an” depending on color) automatically when printing the name of a fuse in some other context.


Your definition for filled is currently

Definition: a socket is filled rather than unfilled if a socket contains a fuse.

but this probably doesn’t do what you want because the compiler won’t know that the second “a socket” is the same as the first. Try

Definition: a socket is filled rather than unfilled if it contains a fuse.

You could also set up a similar definition for fuses:

Definition: a fuse is plugged-in rather than loose if it is contained by a socket.

It looks like your rule that starts with

before taking:

is trying to actually describe how a successful action should work. See Writing with Inform 12.2 How actions are processed for an overview of the various action processing rulebooks; the default processing cycle is really one of the first things you need to understand. It’s also important to understand how rule preambles work, so see WWI 19.7 The preamble of a rule for an overview.

You’ve already set up some good pieces, and it seems like you actually just want a few additional things to happen. In this case, there’s no need to stop the action, so you probably would want to use a different rulebook than Before. Since the changes are a direct consequence of the action happening and don’t themselves need to print out any text, Carry out is a good choice.

First Carry out taking a plugged-in fuse (called F):
	let SO be a random socket containing F; [sets SO as a temporary/local variable]
	[... need to determine associated indicator I and switch SW here]
	now I is switched off;
	now SW is switched off.

The transfer of the fuse to inventory and printing of “Taken.” will happen as normal via the Standard Rules.

I left out some stuff in that sketch of a rule, which is how to determine which indicator and switch goes with a given socket. This is the realm of relations in Inform, one of the fundamental concepts and a huge advantage over typical languages. It’s not very clear to me exactly what your code is supposed to be doing – maybe you’re trying to relate groups of different types of objects by a common ID?

If that’s the case, I would recommend a more direct approach because it doesn’t seem like the relationships will change during play. Maybe something along the lines of:

Signal transmission relates one indicator (called the signal-receiving indicator) to one socket. The verb to generate the signal for means the reversed signal transmission relation. The verb to receive its signal from means the signal transmission relation.

which would be repeated for other type-to-type relations. (See WWI 13 Relations.)

You need to assert the relationships between specific objects in your code, e.g.

socket0 generates the signal for indicator0.

With that in place you could add things like the following to the sketched rule:

let I be the signal-receiving indicator of SO;

You would need similar code to link switches to sockets.


There’s definitely more, like how to handle the equivalent of functional arguments in phrases (see WWI 11.3 Pattern matching) and the powerful “matched as” construction (see WWI 12.10 Action variables), but I’m guessing that all this advice is getting overwhelming.

There’s a talk by Allison Parish linked in the pinned “Inform documentation and resources” thread that’s a very good crash course on core concepts which are discussed fairly late in Writing with Inform, but which are the real heart of the language. There’s plenty of good stuff on that thread, in general, so you might want to look it over.

The above isn’t supposed to translate as “RTFM!” Initial disorientation is pretty typical for people who are used to other programming languages. Don’t hesitate to post more questions.

2 Likes

I found this Programmer’s manual useful when I had an idea of what I wanted in programming terms (e.g. a function) and needed to know how to do it in Inform 7 terms (a to ___ phrase).

The "--/fuse" notation accepts (in my example) both aqua and aqua fuse as referring to that fuse. Note that your printed name being "aqua fuse" will automatically accept aqua, aqua fuse, and fuse as referring to the fuse when there is no disambiguation needed.

I want to thank everyone for their advice. I learned an awful lot.

I will look at the programmer’s guide to inform as well.

Revisiting this because I don’t think we ever fully addressed one of the main parts of the OP’s question:

WI §4.15 Assemblies and body parts deals with just this sort of thing.

One of the (I thought) interesting wrinkles in the OP is the shared properties of the various parts of the assembly (the common, but differently-labeled id number, and the color). Although, as @Otistdog points out, relations are a strong suit of the language, I don’t think what your doing here necessitates their use. It just looks like you have a bunch of objects which start out with related properties and you want to be able to refer to and match them in your code. While one could simply hand-code these, avoiding repetitive code was the original goal.

Unfortunately, when creating assemblies, we aren’t allowed something like:

The color of a socket is initially the color of the holder of the item described.
[or]
The color of a socket is usually the color of the holder of the item described.
[or]
The color of a socket (called S) is usually the color of the holder of S.

Any of the above will yield this error message:

… this seems to say two different properties are not simply equal but somehow the same thing, like saying that ‘the printed name of the millpond is the printed name of the village pond’. This puts me in a quandary: which should be changed to match the other, and what if I am unable to work out the value of either one?

Of course we could just give all the parts the color property and then change them from the default to the desired value with a “When play begins rule” to loop through them programmatically, but this seems wasteful and prone to bugs.

Instead, we can just make aliases of the original parent object’s number and color, but now we don’t have a built-in way to refer to them when parsing the name of the object. Even if we set up a relation, we aren’t currently allowed to use relations with kinds of value in “Understand” grammar lines. We can, however use the reverse incorporation relation (as I’ve done below) to “borrow” any property-understanding we’ve given to the parent object and use it for its parts.

The result of all of this may seem pretty verbose; but, adding new Electrical closets (six total?) is as easy as creating an Electrical closet and giving its panel a color and number.

(code too long for a shareable Borogove snippet)
Part 1 - Setup

[Based on code originally posted by Dana Montgomery (@dmontgom22) on:
https://intfiction.org/t/abstracting-objects/72809]

Section 1 - Options

[Release along with cover art, a website, an introductory booklet, and an introductory postcard.]

Use scoring.
Use American Dialect.
Use serial comma.
The maximum score is 100.
The block giving rule is not listed in the check giving it to rules.

[Sound of Bell is the file "StrongmanBell.ogg".]

Section 2 - KOVs

Color is a kind of value. The colors are nondescript, aqua, crimson, emerald, gray, indigo, khaki, and magenta. [putting nondescript first in this list makes it the default.]

Part 2 - Electrical Panels

Section 1 - Electrical Panel Kind

An electrical panel is a kind of openable lockable container.
An electrical panel is usually closed, locked, scenery.

An electrical panel has a color. [<- will default to nondescript]
An electrical panel has a number called a panel id. [<- will default to 0, the default value for numbers]

[Later on in the code, these "understand" lines will be extended to all the components of the panel.]
Understand the panel id property as describing an electrical panel.
Understand the color property as describing an electrical panel.

The printed name of an electrical panel is "Electrical Panel [the panel id]".

The description of an electrical panel is "Electrical Panel [the panel id] is a standard issue 200 amp electrical panel supplying 220 power throughout the ride. The electrical panel is [if the item described is open]open. Inside the panel you see a switch, a socket, and an indicator light.[otherwise]closed.[end if] [if the item described is locked]There are screws holding it shut.[otherwise]The screws for the doors are gone.[end if]".

Every electrical panel is unlocked by the swiss army knife.

Definition: A thing is panel-fitted if it is incorporated by an electrical panel.

[The following won't actually give all the panel's components a color property matching the panel, but it will allow us to refer to a "shared color" of these components and get the desired result.]
To decide what color is --/the shared color of --/a/the (PT - a panel-fitted thing):
	decide on the color of the holder of PT.

Section 2 - Sockets

A socket is a kind of open container. A socket is part of every electrical panel.
A socket is always fixed in place.
The carrying capacity of a socket is always 1. [<- since we'll only allow fuses, this will mean at most exactly one fuse per socket without adding additional rules.]

[As corrected by Otistdog:]
Definition: a socket is filled rather than unfilled if it contains a fuse.

[Instead of a separate property, we just make the socket id an alias of the panel id of the panel which incorporates it.]
To decide what number is --/the socket id of (S - a socket):
	decide on the panel id of the holder of S.
	
The description of a socket is usually "Socket [the socket id of the item described] is part of electrical panel [the panel id of the holder of the item described].[if unfilled] A fuse probably goes in here.".

The printed name of a socket is "socket [the socket id of the item described]".

[What we did above allows for refering to a "socket id," but, since it's not an actual property of a socket, we can't use it in understand rules. Since we want to be able to refer to a socket as "socket 1" we need to cheat a bit here. This will allow us to tack on the name of the panel before or after "socket". Since we can understand the panel by its number or color, these will now be extended to the socket. Note that you could even say "examine socket electrical panel 1" and it would be understood as the appropriate socket.]
Understand "socket [something related by reversed incorporation]" as a socket.
Understand "[something related by reversed incorporation] socket" as a socket.

[This will allow us to refer to the "corresponding" socket, switch, or indicator; i.e. the one from the same panel. This particular phrase works because there is only ever one each of these in a panel. If we decide later to have, say, three sockets per panel, only this phrase will have to be changed -- using more complex logic -- but the rest of the code could be left as-is.]
To decide what thing is --/the corresponding (name of kind of value K) of --/the (PT - a panel-fitted thing):
	let H be the holder of PT;
	decide on a random K that is part of H.[<- there will only ever be one of these]
	

Section 3 - Switches

A switch is a kind of device. A switch is part of every electrical panel.
A switch is fixed in place. 
A switch has a truth state called points awarded. Points awarded is usually false.

To decide what number is --/the switch id of (S - a switch):
	decide on the panel id of the holder of S.

[We do the same thing we did with sockets, above.]
Understand "switch [something related by reversed incorporation]" as a switch.
Understand "[something related by reversed incorporation] switch" as a switch.
	
The description of a switch is "Switch [the switch id of the item described] is part of electrical panel [the switch id of the item described]. It[']s a big switch. You could probably turn it [if the item described is switched off]on[otherwise]off[end if] if you wanted to."

The printed name of a switch is "Switch [the switch id of the item described]".

	
Section 4 - Indicators lights

[Since an indicator is really just a light and can't be "switched on/off" by the player, we don't really need to make it a device. We'll just make it's appearance tied to the switch on the same panel. That way, we don't need to worry about keeping them in sync.]

An indicator is a kind of thing. An indicator is a part of every electrical panel.
An indicator is fixed in place.
To decide what number is --/the indicator id of (I - an indicator):
	decide on the panel id of the holder of I.
	
The description of an indicator is "Indicator [the indicator id of the item described] [if the corresponding switch of the item described is switched on]is glowing [shared color of the item described] and is currently indicating something[otherwise]is currently indicating nothing[end if]."

The printed name of an indicator is "Indicator [the indicator id of the item described]". 

[again]
Understand "indicator [something related by reversed incorporation]" as an indicator.
Understand "[something related by reversed incorporation] indicator" as an indicator.

	
Part 3 - Electrical Closets

An electrical closet is a kind of room. Every electrical closet contains an electrical panel (called its electrical panel). [<- this last parenthetical part allows us to refer in the code to a particular electrical panel using "<room>'s electrical panel". See below. We didn't need to do this for sockets because this is automatic in cases of incorporation.]

Part 4 - Fuses

A fuse is a kind of thing.
A fuse can be lost or found. A fuse is usually lost. 
A fuse has a color. 
A fuse has a number called fuse id.
The description of a fuse is "This is a [color] colored electrical fuse." 
The printed name of a fuse is "[color] colored fuse".

Understand "fuse" as a fuse. 
Understand the color property as describing a fuse.

Part 5 - Special Consequences of Actions

Section 1 - Panels
	
After unlocking an electrical panel with something (this is the report unlocking an electrical panel rule):
	say "Using the screwdriver on the Swiss Army knife, you remove the screws to the cover of the electrical panel.".
		
Section 2 - Fuses

The taking action has an object called the object taken from.

Setting action variables for taking (this is the set object taken from rule):
	now the object taken from is the holder of the noun.

After taking a fuse when the object taken from is a socket (this is the check switch after removing fuses rule):
	say "Taken.";
	if the corresponding switch of the object taken from is switched on:
		now the corresponding switch of the object taken from is switched off;
		say "[Corresponding indicator of the object taken from] just went out.".
	
Section 3 - Sockets

Check inserting something into a socket (this is the can only insert fuses into sockets rule):
	if the noun is not a fuse, say "That won[']t fit in the socket." instead.

After inserting a fuse into a socket when the color of the noun is the shared color of the second noun (this is the matching fuse snick rule):
	say "You hear a satisfying snick as the fuse slides into place.".

[This is already the default response]
[instead of examining a socket (called the socket) when the socket is unfilled, say "Socket [socket id of the noun] is empty." instead.]

[There is already a rule for this using the built-in carrying capacity, but the response is different.]
[check inserting a fuse into a socket:
	if the socket is filled, say "But Socket [socket id of the second noun] is already full." instead.]

[Also has a similar default response:]	
[instead of examining a socket (called the socket) when the socket is filled, say "Socket [socket id of the noun] contains [a list of things in the noun]." instead.]

Section 4 - Switches and Indicators

Instead of pushing a switched off switch (this is the redirect push to switch on rule):
	try switching on the noun.

Instead of pushing a switched on switch (this is the redirect push to switch off rule):
	try switching off the noun.

To decide if (S - a socket) is properly fused:
	if S is filled:
		let F be a random fuse in S;[<- can only be 1]
		if the color of F is the shared color of S:
			decide yes;
	decide no.
	
Check switching on a switched off switch (this is the nothing happens unless socket is properly fused rule):
	unless the corresponding socket of the noun is properly fused:
		say "Nothing obvious happens." instead.

Last report switching on a switch (this is the final report switching on a switch rule):
	say "[Corresponding indicator of the noun]'s light goes on.";
	if points awarded of the noun is false:
		[play the sound of Bell;]
		increase score by 5;
		now points awarded of the noun is true.

Last report switching off a switch (this is the final report switching off a switch rule):		
	say "[Corresponding indicator of the noun]'s light turns off.".
	

Part 6 - Setting

[unfinished]

Electrical Room is a room. "This is the Electrical Room".
Electrical Room is south of the Generator Room. 

Every turn when the location is the electrical room (this is the describe electromagnetic enery rule):
	say "This room is oozing with electromagnetic energy. You can feel your hair stand on end and all your nerves twitching. This feels dangerous! There are exits in all directions."

The Swiss Army knife is in the Electrical Room. The printed name is "Swiss Army knife".
 
The screwdriver, the awl, fingernail clippers, the can opener, and the corkscrew are part of the Swiss Army knife. Understand "screwdriver" as knife. 

The description of the Swiss army knife is "This is the standard issue Swiss Army knife. It has [a list of things which are part of the item described]." 

[We want to call these "a fuse1," etc. so that the indefinite article gets correctly set and will automatically adjust to the color, i.e. "an aqua" or "a crimson"]
An aqua fuse called a fuse1 is in the electrical room. The fuse id of fuse1 is 1.
A crimson fuse called a fuse3 is in the electrical room. The fuse id of fuse3 is 3. 
	
An electrical closet called Electrical Closet One is northeast of the electrical room. "This is Electrical Closet One. There[']s an electrical panel here and an exit to the south west."
Electrical Closet One's electrical panel is aqua. It has panel id 1.

The silver key is in Electrical Closet One. The description of the silver key is "This is a small silver key. I wonder what it unlocks."

An electrical closet called Electrical Closet Three is east of the electrical room. "This is Electrical Closet Three. There[']s an electrical panel here and an exit to the west."
Electrical Closet Three's electrical panel is crimson. It has panel id 3.

		
Test start with “get knife, aqua, crimson / ne / x panel / unlock panel with knife / open panel 1 / x panel".
Test aqua with "put aqua in socket / x panel / x indicator / push switch / x indicator / get aqua fuse / x aqua indicator”.
Test crim with "put crimson in socket / x panel / x indicator / push switch 3 / x indicator”. 

Test me with "test start / test aqua / test aqua / sw / e / test crim / put aqua fuse in socket 3 / get fuse / put aqua fuse in crimson socket / switch on switch / push crimson switch".

BadParser,

wow! There’s a lot there to digest.

Thank you SO much for taking the time to correct and annotate my code. This community is awesome!

Last night i discovered “Understand the color property as describing a fuse” myself.

I’m heading back to read it again.

d.

2 Likes