Kapitel 5: Das Standardverhalten ändern

Wenn der Spieler einen Befehl eingibt, führt das (nach der Übersetzung durch einen Parser) zum Aufrufen einer oder mehrerer “Regeln”. Diese Regeln regeln das Standardverhalten in der Welt: Dinge, die sich in Reichweite befinden, kann man nehmen, wenn sie tragbar sind; sonst nicht. Essbare Dinge, die man mit sich führt, kann man essen; danach sind sie weg. Versucht man etwas zu essen, das nicht essbar ist, führen die Regeln zu einer entsprechenden Ausgabe an die Konsole – “You can’t eat that” oder so ähnlich. Und wenn man von einem Raum aus in eine bestimmte Himmelsrichtung geht, entscheiden die Regeln darüber, was geschieht – in der Regel kommt man an einen neuen Ort, wenn es den in dieser Himmelsrichtung gibt; ansonsten kriegt man die lapidare Meldung, dass das nicht geht.

Wenn man interessante Geschichten haben möchte und mit der Spielwelt auf interessante Weise interagieren möchte, muss man dieses Standardverhalten ändern. Man kann einen Weg zum Beispiel nur dann gehen, wenn bestimmte Bedingungen erfüllt sind.

Mit selbst geschriebenen Regeln ändert man das Verhalten der Welt. Am häufigsten sind das Instead-Regeln. Eine Instead-Regel wird, etwas vereinfacht gesagt, statt der eigentlich vorgesehenen Regeln angewendet. Hier ein paar Anwendungsbeispiele.

Hier kommst du nicht vorbei

Häufig möchte man, dass ein bestimmter Weg erst dann möglich wird, wenn bestimmte Bedingungen erfüllt sind. Unser Wolf soll erst zu den Geißlein kommen können, wenn er die Kreide gefressen hat und das weiße Kapuzenshirt trägt.

Allgemein:

Instead of going west from the Entrance Area:
	Say "You can't go there."

Das verbietet das Gehen unter allen Umständen. Das ist zu streng:

Instead of going west from the Entrance Area:
	If the player is wearing the white hoodie:
		Continue the action;
		[regulär weitermachen, also den Spieler bewegen]
	Otherwise:
		Say "You can't go through there. From inside, you hear voices shouting: 'No, you're not our mother. Our mother has got white skin.'"

Bei der Syntax muss man eigentlich nur beachten, dass jede Zeile mit einem Strichpunkt (nach einer Anweisung) oder Doppelpunkt (nach einer Kontrollstrukur) endet; ein Punkt kommt erst ganz am Schluss. Punkte innerhalb von Anführungszeichen gelten dabei nur als solche, wenn sie ganz am Schluss des Strings stehen.

Neben “wear” (im Sinne von: an haben) kennt Inform 7 unter anderem noch “carry” (in der Hand tragen), “have” (mit sich führen, in der Hand oder im Rucksack), “contain” (enthalten). Letzteres braucht man zum Beispiel bei “if the box contains the diamond”.

Allerdings muss der Wolf ja zwei Bedingungen erfüllen, mit jeweils unterschiedlicher Folge. Das geht zum Beispiel mit verschachtelten bedingten Anweisungen:

Instead of going west from the Entrance Area:
	If the player is wearing the white hoodie:
		If the voice of the player is low:
			Say "You can't go through there. [line break]From inside, you hear voices shouting: 'No, you don't sound like our mother.'"; [Strichpunkt nicht vergessen]
		Otherwise:
			Continue the action;
			[regulär weitermachen, also den Spieler bewegen]
	Otherwise:
		Say "You can't go through there. [line break]From inside, you hear voices shouting: 'No, you're not our mother. Our mothers has got white skin.'"

Jetzt klappt das auch mit dem Wolf und unser Spiel ist fast fertig. Wir müssen dem Wolf nur noch die Möglichkeit geben, seine Stimme zu erhöhen. Änderungen bei den Variablenwerten macht man mit dem Schlüsselwort now:

Instead of eating the piece of chalk:
	Now the voice of the player is high;
	Say "You feel a bit funny.";
	Remove the chalk from play.

Statt der letzten beiden Zeilen hätte man auch Continue the action. schreiben können. Dann wäre die Kreide auch weg und die Standardantwort würde ausgedruckt werden.

Auftauchende Gegenstände

Häufig möchte man auch, dass Gegenstände erst unter bestimmten Bedingungen auftauchen, oder dass sie verschwinden. Das geht so:

Instead of inserting [something] into the well:
	Remove the noun from play;
	If the noun is the ball:
		Now the frog is in the location of the player;
		Say "A frog appears next to you.";
	Otherwise:
		Say "You listen to the [noun] going down. And then the [noun] is gone."

Dabei steht [something] für: ein sichtbares und erreichbares Objekt der Klasse thing (oder Unterklassen davon). Wenn es bei der Regel nur um ein konkretes Objekt geht, nimmt man einfach dessen Bezeichner.
Ansonsten kann man noch [somebody] für Personen oder Tiere nehmen und [somewhere] für eine beliebige Himmelsrichtung.

Mit Personen reden

[Kommt später mal.]

Bislang lautet der vollständige Quellcode so:

"The Wolf and the Seven Kids" by Moritz.

The Wolf Cave is a room. "Here is your home. You got nearly everything in this cave that you need to invade the seven little kids. Light comes in from the west." West of the Wolf Cave is the Forest.

The Forest is a room. "This place is very large and it is dark here. You can go north, east, south and west. You can hear birds singing." South of the Forest is the Marketplace. West of the Forest is the Entrance Area. North of the Forest is the River.

The River is a room. "Here is a place where you can relax. Every time you did hard work, you can lie down next to the river and chill. A road leads south to a forest."

The Marketplace is a room. "You should not stay here for too long, because the mother of the kids is often here to buy some food. If she sees you, she will bump the shit out of you. In the north, you can see the trees of the forest."

The Entrance Area is a room. "Now you are in front of the house where the kids live. You have to go west to enter the house, or you can go east to the forest." West of the Entrance Area is the Kid House.

The Kid House is a room. "A nice house. There is only one room, and the exit is west."

The red hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a red hoodie. A hoodie is a sweater with a hood."

The black hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a black hoodie. A hoodie is a sweater with a hood."

The white hoodie is a thing. It is wearable. It is in the Wolf Cave. The description is "This is a white hoodie. A hoodie is a sweater with a hood."

The piece of chalk is a thing. It is in the Marketplace. It is edible. The description is "Here is some chalk. You can use it, to write on a blackboard. If you eat it, your voice will get temporarily high and female."

The dripping cave ceiling is scenery in the Wolf Cave. The description is "There are drops at the ceiling. The whole cave is very wet and you can hear the drops hitting the ground."

The trees are scenery in the Forest. The description is "Lots of trees, some old, some new. Some have hearts cut into them." Understand "tree" as the trees.

The birds are scenery in the Forest. The description is "Small bodies that hop from tree to tree."

A goat-kid is a kind of thing. It is always edible. The description usually is "A poor, helpless little kid. Baaa-ahh." The indefinite article is "the".

The first kid, the second kid, the third kid, the fourth kid, the fifth kid, the sixth kid and the seventh kid are goat-kids in the Kid House.

Pitch is a kind of value. The pitches are high, middle and low.
The player has a pitch called voice. The voice of the player is low.

Instead of going west from the Entrance Area:
	If the player is wearing the white hoodie:
		If the voice of the player is low:
			Say "You can't go through there. From inside, you hear voices shouting: 'No, you don't sound like our mother.'"; [Strichpunkt nicht vergessen]
		Otherwise:
			Continue the action;
			[regulär weitermachen, also den Spieler bewegen]
	Otherwise:
		Say "You can't go through there. From inside, you hear voices shouting: 'No, you're not our mother. Our mother has got white skin.'"

Instead of eating the piece of chalk:
	Now the voice of the player is high;
	Say "You feel a bit funny.";
	Remove the chalk from play.

Anhang: Weitere Regeln.

Die meisten Regeln sind schon fest eingebaut. Man muss sie nicht kennen, man muss nicht einmal wissen, welche es gibt, aber für das spätere Eingreifen in die feste Regelwelt ist etwas Hintergrundwissen nützlich.
Es gibt unter anderem Check-, Carry-Out- und Report-Regeln. Sie werden hier für die Aktion etwas essen vorgestellt.

Check-Regel: Vor dem Ausführen der Aktion

Die Check-Regel zu einer Aktion bestimmt, ob die Aktion überhaupt ausgeführt werden kann. Essen kann man nur Essbares, das schreibt man in Inform so:

Check an actor eating (this is the can’t eat unless edible rule):
	if the noun is not a thing or the noun is not edible,
		stop the action with library message eating action number 1 for the noun.

Wenn die Check-Regel bestanden wird, geht die Aktion weiter an die nächsten Regeln:

Carry-Out-Regel: Das Ausführen der Aktion.

Die Carry-Out-Regel zu einer Aktion bestimmt, was durch das Ausführen der Aktion in der Modell-Welt verändert wird. Gegessene Objekte verschwinden:

Carry out an actor eating (this is the standard eating rule):
	remove the noun from play.

Danach geht die Aktion weiter an die nächsten Regeln:

Report-Regel: Textausgabe nach der ausgeführten Aktion.

Die Report-Regel zu einer Aktion bestimmt, was nach der Ausführung als Text ausgegeben werden soll.

Report an actor eating (this is the standard report eating rule):
	if the actor is the player, issue library message eating action number 2 for the noun;
		otherwise issue actor-based library message eating action number 3 for the noun.

Check-, Carry-Out- und Report-Regeln schreibt man selber nur dann, wenn man neue Aktionen erfindet, die von den Inform-Standardregeln nicht vorgesehen sind.


Außerdem gibt es unter anderem noch Regeln vom Typ “When” und “Every turn”:

When play begins:
	Say "Welcome to my game."

Every turn when the player is carrying the piano:
	Say "Uuuuh. That's heavy."

Schreibe einen Kommentar