Switch, Switch/Turn on and Switch/Turn off

I am experiencing problems dealing with something very trivial. I have a switch which the player should be able to switch, and a flashlight which the player should be able to switch and/or turn on and off. The verb section goes

Section - Switch

Understand the command "switch" as something new. Switching is an action applying to one thing. Understand "switch [something]" as switching. Understand "switch [something]" as switching.
Check switching:
	say "That's not something you can switch!" instead.

Section - Switch/Turn on

Einschalten is an action applying to one thing. Understand "switch on [something]" and "switch [something] on" and "turn [something] on" and "turn on [something]" as einschalten.
Check Einschalten:
	say "That's not something you can turn on!" instead.

Section - Switch/Turn off

Ausschalten is an action applying to one thing. Understand "switch off [something]" and "switch [something] off" and "turn [something] off" and "turn off [something]" as ausschalten.
Check Ausschalten:
	say "That's not something you can turn off!" instead.

and the flashlight looks like this (including plenty unnecessary crap code after some attempts):

A flashlight is a switched off device. It is on the shelves. The description of the flashlight is "A MagLite. As long as your forearm and quite heavy.". 
Check einschalten the flashlight:
	if the flashlight is lit:
		say "But it is already lit!" instead;
	now the flashlight is lit;
	say "You turn on the flashlight." instead.
Check ausschalten the flashlight:
	if the flashlight is lit:
		now the flashlight is unlit;
		say "You turn off the flashlight." instead;
	say "But it's not even turned on!" instead.
Check turning the flashlight:
	if the flashlight is lit, say "It's already on." instead;
	now the flashlight is lit;
	say "You turn on the flashlight." instead.
Check switching off the flashlight:
	if the flashlight is lit:
		now the flashlight is unlit;
		say "You turn off the flashlight." instead;
	say "But it's not even turned on!" instead.

“Switch switch” works, “turn/switch on flashlight” works, and “switch off flashlight” works, but “turn off flashlight” results in “I didn’t understand that sentence.” What have I done wrong?

Thanks and kind regards,
Grues

You’ve alerted the compiler that the verb word “switch” should be treated as something new, but not the verb word “turn”.

If you look in the Index / Actions tab / A2 Alphabetic, you’ll see that there are several actions set up:

ausschalten
einschalten
switching
switching on
switching off

Clicking the magnifier icon next to one will show more about that action, specifically what typed commands can trigger it. As an example, for einschalten (your action):

Typed commands leading to this action

"switch on [something]" 
"switch [something] on" 
"turn/rotate/twist/unscrew/screw [something] on" 
"turn/rotate/twist/unscrew/screw on [something]"

and for switching on (from the Standard Rules):

Typed commands leading to this action

"turn/rotate/twist/unscrew/screw [something] on"
"turn/rotate/twist/unscrew/screw on [something]"

As you can see, you ended up with the same grammar (in some cases) pointing to different actions. That means that the parser’s choice of applicable action is a matter of when the grammar lines appear in the source code, and I think (but I’m not sure) that author-defined actions always come later than those in the Standard Rules.

FYI – here’s the section in the Standard Rules that deals with “turn” and its synonyms:

Understand "turn [something]" as turning.
Understand "turn [something] on" or "turn on [something]" as switching on.
Understand "turn [something] off" or "turn off [something]" as switching off.
Understand the commands "rotate", "twist", "unscrew" and "screw" as "turn".

The doubled-up grammar comes from where you say:

Understand ... and "turn [something] on" and "turn on [something]" as einschalten.

This combines with the Standard Rules line:

Understand the commands "rotate", "twist", "unscrew" and "screw" as "turn".

to create the unexpected variations for einschalten seen in the Index.

It seems more likely that you will want to use the existing actions from the Standard Rules than to define your own in this case. (If you’re just looking to translate verbs into German, perhaps there is a German translation?) If you’re not sure which actions come with the Standard Rules, the Index can help – just start a new project defining only one room, compile, and check out the Actions tab.

As an aside, cramming all of the action processing logic into Check rules is a not a good strategy. See WWI 12.2 How actions are processed for an overview of the approach for which the Standard Rules’ action-processing rulebooks are designed. It may seem inefficient from an Inform 6 perspective to split the code up into different chunks for checking, carrying out and reporting, but it’s vital as a method of managing overall complexity of action-processing code interaction in the Inform 7 paradigm.

3 Likes

That was comprehensive, and it helped. Thanks a very lot!