StoriEd Intermediate Form
From EQUIS Lab Wiki
This page describes the intermediate language used by the StoriEd game engine to actually execute games. This intermediate form is compiled from a high-level game description. Examples in this section derive from this StoriEd Scenario.
The intermediate language is rule-based. The runtime engine monitors a set of rules. When rules are triggered, actions are carried out. We first show the possible actions, then consider the rules.
Contents |
Actions
Actions are triggered by user actions, either by clicking on an active object in a scene, or selecting an option in a dialogue. Actions are used to manipulate the pool of plot tokens, play sounds, initiate new dialogues, and change scenes. The following actions may be performed.
Set
Set sets one or more plot tokens. Tokens are used in dialogues to determine what point of the plot or dialogue we have reached. Above, when we set "Door Dialogue", we specify that the door dialogue is to be active, and it will appear on the screen.
Example:
<set> <token name="Door Dialogue" /> <token name="We owe John Brown money" /> </set>
Unset
Unset unsets one or more tokens. For example, if we were to pay John Brown, we would no longer owe him money. If we unset the door dialogue, the dialogue will disappear from the screen.
Example:
<unset> <token name="We owe John Brown money" /> <token name="Door Dialogue" /> </unset>
Play
Play plays a sound file. This is intended to allow simple sound effects to be added to the game. For example, opening a door might play the sound of a creaking door opening.
Example:
<play file="openDoor.wav" />
PlayLooping
PlayLooping plays a sound file repeatedly. The sound plays continuously until another PlayLooping directive is issued. If no name is given, sound stops.
Examples:
<playlooping file="birds.wav" /> <playlooping file="" />
SetActionMap
SetActionMap sets the action map to be used to translate player inputs. When a player clicks on one of the active objects defined by the action map, the command
<set token="Player clicked: hhhhhh" />
is executed, where "hhhhhh" is the hexadecimal RGB representation of the colour that was clicked. SetActionMap would normally be used in conjunction with SetBackgroundImage.
Example:
<setactionmap file="collegeCourtyardActions.png" />
SetBackgroundImage
SetBackgroundImage sets the image to be used as the scene background. This would normally be used in conjunction with SetActionMap.
Example:
<setbackgroundimage file="collegeCourtyard.png" />
You've hit the ball out the park! Icnredilbe!
Rules
Rules invoke actions when their conditions are met. To fire, rules must match a set of specified tokens in the token pool. Whenever the token pool changes, the runtime engine determines which rules are eligible to fire.
If multiple rules match at any given time, the runtime engine always picks the rule that matches the most plot tokens. If there is a tie, one of the rules matching most tokens is picked at random.
Initially
A game may have one initially rule which fires when the game starts. This is used to set the game's initial state. The example below sets up an initial scene.
Example:
<initially> <actions> <set> <token name="Scene: college courtyard" /> </set> <setbackgroundimage file="collegeCourtyard.png" /> <setactionmap file="collegeCourtyardActions.png" /> <playlooping file="birds.wav" /> </actions> </initially>
Rule
Rules are of the following form. A requires list specifies the tokens that must match before the rule is fired. The actions list species the actions that are performed if this rule is fired.
<rule> <requires> <token name="t1" /> ... <token name="tn" /> </requires> <actions> action1 ... actionN </actions> </rule>
The following rule specifies that if the user clicks on the red ("FF0000") active object in the college courtyard scene, the open door dialogue is to appear. The rule matches if both the "Scene: college courtyard" and "user clicked FF0000" tokens are in the tokens pool. If the rule fires, it first removes the user input (unsetting the "user clicked FF0000" token) so that the rule fires only once, and then initiates the door open dialogue.
Example:
<rule> <requires> <token name="Scene: college courtyard" /> <token name="User clicked: FF0000" /> </requires> <actions> <unset> <token name="User clicked: FF0000" /> </unset> <showdialogue name="Open College Door"> <icon file=doorIcon.png" /> <maintext> <text>Would you like to enter the door?</text> </maintext> <answer> <text>Yes</text> </answer> <answer> <text>No</text> </answer> </showdialogue> </actions> </rule>
Then when the player selects the answer, a new token is entered into the plot tokens pool. A set of actions is followed depending on which answer the player clicked. The following rule specifies that if the player click on the "No" response, the door dialogue is then disappear but nothing else is changed. The rule matches if the "user answered open college door no" token is in the tokens pool. If the rule fires, it first removes the user input (unsetting the "user answered open college door No"and "Door dialogue" tokens) so again, the rule fires only once and then initiates the door dialogue to be gone.
<rule> <requires> <token name="User answered: Open College Door -> No"/> </requires> <actions> <unset> <token name="User answered: Open College Door -> No"/> <token name="Door Dialogue" /> </unset> </actions> </rule>
The following rules specify the actions followed by a "Yes" response. The door dialogue is disappear and an open door sound is played. Then the player is now entering a new scene with a new background music playing on the back. The rule matches if the "user answered open college door yes" token is in the tokens pool. When the rule fires, it removes the user input and the "Door dialogue" tokens, creates a new token "Scene: College Interior" in a tokens pool and follows a new set of actions.
<rule> <requires> <token name="User answered: Open College Door -> Yes"/> </requires> <actions> <unset> <token name="User answered: Open College Door -> Yes"/> <token name="Dialogue: Door" /> <token name="Scene: College Courtyard" /> </unset> <play file="openDoor.wav" /> <set> <token name="Scene: College Interior" /> </set> <setbackgroundimage file="insideCollege.png" /> <setactionmap file="insideCollege.png" /> <playlooping file="insideCollege.wav" /> </actions> </rule>