|
| 1 | +Chapter 2 : How To Design A New Text Grammar |
| 2 | +============================================== |
| 3 | +In addition to logic files, each game requires a grammar file in which it describes various sentences to be used within |
| 4 | +the game. For example, when the player enters a room, a few lines of the greetings to the game, introduction of the |
| 5 | +room, the items inside the room, etc. are displayed for the player. This text is compiled by a word parser at Inform7 |
| 6 | +using a customized text-grammar file. This file also should be designed by the designer of the game and stored with |
| 7 | +`.twg` extension. |
| 8 | + |
| 9 | +To describe this file, it is better to start with greetings. Greetings is a set of various sentences which will be |
| 10 | +picked by the parser randomly and will be displayed on output anytime the player either enters into the game or enters |
| 11 | +into a room. The greeting should include a general description about the state of the game, the room, or the current |
| 12 | +elements of the game. If the generated sentence requires importation of elements or status of the game, that should |
| 13 | +also be coded into the sentence. The question is how? Here, we practice writing such sentences. |
| 14 | + |
| 15 | +Let's first explore a fixed type of greetings. |
| 16 | + |
| 17 | +.. code-block:: bash |
| 18 | +
|
| 19 | + GREETING : GREETING!;GREETINGS TREKKIE!;HELLO ASTRONAUT!;ALRIGHT THEN!; HEY TREKKIE |
| 20 | +
|
| 21 | +Here, `GREETING` is the code to call the greeting sentence and the right side of semicolon is an array-like of different |
| 22 | +options that the parser can pick between them; e.g. in above example, there are five different options and each time the |
| 23 | +parser randomly picks one of them as the greeting of the game. Each of these five has the same probability; thus, if we |
| 24 | +want to increase the probability of one item, we can repeat that as much as we wish. Moreover, each phrase above is |
| 25 | +fixed and will be used as it is. However, it is possible to have a sentence which can be reformed based on the |
| 26 | +situation. Following is an example of flexible greeting, |
| 27 | + |
| 28 | +.. code-block:: bash |
| 29 | +
|
| 30 | + Flex_greeting : #GREETING#, it is TextWorld |
| 31 | +
|
| 32 | +This example explains that we may have "Greeting!, it is TextWorld" or "HEY TREKKIE!, it is TextWorld", or any other |
| 33 | +combinations that we can mix and match from "Flex_greeting" and "GREETING". In other words, any word (or combination of |
| 34 | +words which are attached by hyphen) and comes in between "#", is like a symbol of another vector of phrases and is |
| 35 | +replaced by the parser with one of the phrases from that vector. Following is another example of the creation of the |
| 36 | +flexible sentence: |
| 37 | + |
| 38 | +.. code-block:: bash |
| 39 | +
|
| 40 | + dec : #GREETING# #dec_type##suffix_(r)#;#dec_type##suffix_(r)# |
| 41 | +
|
| 42 | + dec_type : #reg-0#;#difficult-0# |
| 43 | + suffix_(r) : . Okay, just remember what is your mission here to do, and everything will go great.; \ |
| 44 | + . You try to gain information on your surroundings by using a technique you call 'looking.'; \ |
| 45 | + . You can barely contain your excitement.; |
| 46 | + . The room seems oddly familiar, as though it were only superficially different from the other rooms in the spacecraft.; \ |
| 47 | + . You decide to just list off a complete list of everything you see in the module, because hey, why not?; |
| 48 | +
|
| 49 | + reg-0 : #01#;#02# |
| 50 | + difficult-0 : #03# |
| 51 | +
|
| 52 | + 01 : #dec_find-yourself# in a (name);#dec_guess-what# (name) |
| 53 | + 02 : Well, here we are in #dec_a_the# (name) |
| 54 | + 03 : You're now in #dec_a_the# (name) |
| 55 | +
|
| 56 | + dec_find-yourself : You #dec_what# |
| 57 | + dec_guess-what : #dec_well-guess#, you are in #dec_a_the# place we're calling #dec_a_the# |
| 58 | + dec_a_the : a;the |
| 59 | + dec_what : are;find yourself;arrive |
| 60 | + dec_well-guess : Guess what;Well how about that;Well I'll be |
| 61 | +
|
| 62 | +In this example, assume that the #GREETING# #dec_type##suffix_(r)# is randomly picked, to replace GREETING, dec_type, |
| 63 | +and suffix_(r) variables, respectively, the "HELLO ASTRONAUT!", "reg-0", and ". Okay, just remember what is your mission |
| 64 | +here to do, and everything will go great." are chosen. To replace reg-0, the parser randomly picks "02", and to replace |
| 65 | +"02", the "Well, here we are in #dec_a_the# (name)" is selected. In the latter choice of phrase we have two type of |
| 66 | +variables, one is "dec_a_the" and the other is "(name)". The first has already described and let's assume that "the" is |
| 67 | +picked. For the second, the (name) is replaced by the name of a room that the player is in. Rooms and their names are |
| 68 | +described in next chapter. Finally, the created sentence is as follows: |
| 69 | + |
| 70 | +.. code-block:: bash |
| 71 | +
|
| 72 | + HELLO ASTRONAUT! Well, here we are in the (name). Okay, just remember what is your mission here to do, and everything will go great. |
| 73 | +
|
| 74 | +This sentence is made for a sample state and anytime the game reaches to this state the (name) is replace with the |
| 75 | +corresponding room's name and is printed on the screen. To increase the variety of the outputs, a designer can expand |
| 76 | +those sentence block to more and more options. However, it is always important to notice that these sentences |
| 77 | +should comply with the scenario of the game in general and the specific scene of the game in each state. We recommend |
| 78 | +to make a good use of general sentences, and specific type of sentences which can be fed by variable from the game |
| 79 | +state (between parentheses variables). Following this advice can give better sentence in accordance to the game story. |
| 80 | + |
| 81 | +Although the design of a text-grammar file is more depend on the designer's preference rather than the logic file, yet, |
| 82 | +there are some sections which should be considered in .twg file. The fundamental sections are named as |
| 83 | + |
| 84 | + 1. Expandables : All required combinations, structures, etc of words, letters, and numbers which are used in the whole text of the grammar. |
| 85 | + 2. Verbs : All verbs which are used as action or simply as verb in the text are collected. |
| 86 | + 3. Types & Variables : Type of objects and variables of the game are defined and coded. |
| 87 | + 4. Objects Garmmar : The grammar of each object of the game is defined in this section. |
| 88 | + 5. Room Description Grammar : All the texts which are used to describe the game inside different rooms are defined and expanded. |
| 89 | + 6. Instructions Grammar : The grammar of instructions for compound commands, etc are described. |
| 90 | + |
| 91 | +Expandables are all the variables which comes in between "#"s and expand to create a sentence. Verbs are also some sort |
| 92 | +of expandable in which different synonyms and tense of the verb and its corresponding synonyms are clarified to be used |
| 93 | +in text creation and hesitate from repeating a verb frequently, see below example for "take" verb, |
| 94 | + |
| 95 | +.. code-block:: bash |
| 96 | +
|
| 97 | + take : #take_syn_v# the #obj_types# from the (r).;#take_syn_v# the #obj_types# that's in the (r). |
| 98 | + take_syn_v : take;retrieve;grab |
| 99 | + take_syn_pp : taken;got;picked |
| 100 | + taking : taking;getting;picking |
| 101 | +
|
| 102 | + take/s : #take_syn_v# the #obj_types# from the #on_var#. |
| 103 | +
|
| 104 | + take/c : #take_syn_v# the #obj_types# from the #on_var#. |
| 105 | +
|
| 106 | +"take_syn_v" and "take_syn_pp" respectively refer to the list of synonyms and the past participle of those |
| 107 | +synonyms; the ing-form of the verb is the following line. Similar to the logic file description, if we have to assign a |
| 108 | +word in different application, like take vs. take from a table, these two can be distinguished by assigning different |
| 109 | +code words for each set. To understand this, take a look at above example and compare the definition of "take" with |
| 110 | +"take/s". |
| 111 | + |
| 112 | +Types of all elements in the game can be coded for the grammar to address much easier. For example, "obj_types : (o|k|f)" |
| 113 | +indicates all the object, key, or food with the `obj_types`, while "on_types : (c|s)" refers to container or supporter |
| 114 | +types which object-like can be put `on` it. Recall that the left-side of the semicolon is just a symbolic way of |
| 115 | +representing something which comes on the left-side; so, it is just for text generation and there is no logic behind it. |
| 116 | + |
| 117 | +In "Objects Grammar" section, every element of the game can have their own grammar and customized nouns and adjectives |
| 118 | +to create more sense of the world that the designer tries to build. As an instance, a room can generally be expanded by |
| 119 | +an adjective and a noun; if the game refers to an office (work type of room), then the list of adjective-noun pairs |
| 120 | +could be different, and based on the game story, the designer can add as much as combinations she/he wishes, to add |
| 121 | +more flavour to her/his game. Below is a good example of how different rooms can be assigned with their |
| 122 | +own grammar, |
| 123 | + |
| 124 | +.. code-block:: bash |
| 125 | + # --- Rooms --------------------------------------------------------------------- |
| 126 | + ## List each type of room with a ';' between each |
| 127 | + ## Each roomType must have specific rooms |
| 128 | + ### Creating a room: first, take the name of the roomtype as listed under #room_type# (let's call it X for now). |
| 129 | + ### Then, create three symbols with this: X_(r), X_(r)_noun, and X_(r)_adj. |
| 130 | + ### X_(r) will always be composed of X_(r)_adj | X_(r)_noun. If you want to subdivide a roomtype into two or more variants, you can add _type1, _type2, etc at the end of the noun and adj symbols. |
| 131 | + ### Make sure that these changes are also accounted for in the X_(r) token. |
| 132 | +
|
| 133 | + room_type : clean;cook;rest;work;storage |
| 134 | +
|
| 135 | + (r) : #(r)_adj# | #(r)_noun# |
| 136 | + (r)_noun : sleep station;crew cabin;washroom;closet;kitchenette;module;lab;lounge |
| 137 | + (r)_adj : nondescript;plain |
| 138 | +
|
| 139 | + ### > Rest Room |
| 140 | + ### >> Sleep Room |
| 141 | + rest_(r) : #rest_(r)_adj_type_1# | #rest_(r)_noun_type_1#;#rest_(r)_adj_type_2# | #rest_(r)_noun_type_2# |
| 142 | +
|
| 143 | + rest_(r)_noun_type_1 : sleep station;sleep station;sleep station;sleeping bag;crew cabin |
| 144 | + rest_(r)_adj_type_1 : cozy;relaxing;pleasant;sleepy |
| 145 | + ### >> fun with friends |
| 146 | + rest_(r)_noun_type_2 : lounge;playroom;recreation zone;crew cabin;crew cabin;crew cabin |
| 147 | + rest_(r)_adj_type_2 : fun;entertaining;exciting;well lit;silent |
| 148 | +
|
| 149 | +Majority of the text which is created by the parser belongs to the description of a room. The Room Description Grammar |
| 150 | +expands all the grammar which is used for a room to describe the room as well as the scenario at that room. This process |
| 151 | +is very similar to what we described in Greetings section. |
| 152 | + |
| 153 | +Last but not least is the "Instructions Grammar". This part basically includes all the required grammatical structures |
| 154 | +which the text-based game needs to compound two actions (like unlock and open), separate two sentence from each other or |
| 155 | +to connect them with a word, etc. which are important in the expansion of the sentences all over the game. Following is |
| 156 | +a few examples of what is designed for the Spaceship game: |
| 157 | + |
| 158 | +.. code-block:: bash |
| 159 | + # --- Compound Command Description Functions ------------------------------------ |
| 160 | + ig_unlock_open : open the locked #lock_types# using the (k).; \ |
| 161 | + unlock and open the #lock_types#.; \ |
| 162 | + unlock and open the #lock_types# using the (k).; \ |
| 163 | + open the #lock_types# using the (k). |
| 164 | + ig_unlock_open_take : open the locked #lock_types# using the (k) and take the #obj_types_no_key#.; \ |
| 165 | + unlock the #lock_types# and take the #obj_types_no_key#.; \ |
| 166 | + unlock the #lock_types# using the (k), and take the #obj_types_no_key#.; \ |
| 167 | + take the #obj_types_no_key# from within the locked #lock_types#. |
| 168 | +
|
| 169 | + # --- Separators ----------------------------------------------------------------- |
| 170 | + ## *--- Action separators |
| 171 | + action_separator_take : #afterhave# #take_syn_pp# the #obj_types#, ; \ |
| 172 | + #after# #taking# the #obj_types#, ; \ |
| 173 | + With the #obj_types#, ; \ |
| 174 | + If you can get your hands on the #obj_types#, ; \ |
| 175 | + #emptyinstruction#; |
| 176 | + action_separator_eat : #afterhave# #eat_syn_pp# the #eat_types#, ; \ |
| 177 | + #after# #eating# the #obj_types#, ; \ |
| 178 | + #emptyinstruction#; |
| 179 | +
|
| 180 | + ## *--- Separator Symbols |
| 181 | + afterhave : After you have;Having;Once you have;If you have |
| 182 | + after : After; |
| 183 | +
|
| 184 | +For further details on these expandables, please check the TextWorld's Spaceship game. |
0 commit comments