home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / games2 / trellis / Instructs / Part4 < prev    next >
Encoding:
Text File  |  1994-09-16  |  21.7 KB  |  548 lines

  1.  
  2.                         TRELLIS - The Adventure Interpreter
  3.                       (c) copyright 1991-4 Soft Rock Software
  4.  
  5.                                  TScript Commands
  6.                                  ----------------
  7.  
  8. In this section each of the TScript commands will be explained. Where 
  9. appropriate, examples will be given. For further examples, please see the 
  10. game that has been supplied free with the Trellis.
  11.  
  12. Following the command descriptions you will find some other general hints
  13. for writing TScript programs.
  14.  
  15. ---------------------------------------------------------------------------
  16.  
  17. STOP - this command stops execution of the script file, and returns
  18. control  to the RISC OS desktop without going through the 'do you want to
  19. play again' ritual.
  20. ---------------------------------------------------------------------------
  21.  
  22. LET - this command allows the software's variables to be changed. It has
  23. the format:-
  24.  
  25. LET Variable=Equation
  26.  
  27. where Variable is one of the variables that can be redefined in the script
  28. program. These are explained more fully in part 3, but to summarise, they
  29. are:-
  30.  
  31.  Store%( )                 North%( )                 East%( )
  32.  South%( )                 West%( )                  Up%( )
  33.  Down%( )                  Room$( )                  Light%( )
  34.  List$( )                  Examine$( )               Weight%( )
  35.  Location%( )              Object$( )
  36.  
  37. The number that goes between the brackets with each of these variables can
  38. be an Equation. Both this Equation, and the one following the '=' can
  39. contain any of the above variables, manipulated in many ways. For example,
  40. you can add the contents of two stores together:-
  41.  LET Store%(54)=Store%(43)+Store%(44)
  42. or redefine an exit, to close a door:-
  43.  LET East%(12)=0
  44. or change the short description of an object:-
  45.  LET List$="a broken stick"
  46.  
  47. Equations can also use all the functions made available by the Basic
  48. Interpreter in your computer. For full details of these, please read the
  49. BBC Basic Guide, supplied by Acorn. The one that is most likely to be
  50. useful is RND( ) which can be used to get a random number. You could have
  51. a line:-
  52.  LET Store%(22)=RND(6)
  53. which would be like rolling a dice, and putting the number on top in the
  54. variable called Store%(22).
  55.  
  56. There are 4 important points to remember about variables and equations.
  57.  
  58. (1) The variables that have a percent sign (%) in their name are called
  59. Integer variables. That means they can only contain whole numbers. If you
  60. try to put 1.43 into an integer variable, it will only hold 1. If you try
  61. to put letters or words in, the program will not work properly.
  62.  
  63. (2) The variables that have a dollar sign ($) in their name are called
  64. String variables. That means they contain letters, words and other text.
  65. This is usually enclosed inside speech marks ("). If you try to put 1.43
  66. into a sting variable the program will not work properly. However, you
  67. could put "1.43" in.
  68.  
  69. (3) On a line that starts off with LET, if the Variable on the left of the
  70. equals sign is an Integer one, all the variables used in the equation on
  71. the right should also be integer variables. The reverse is true for
  72. Strings.
  73.  
  74. (4) Wherever there is a variable with an equation in its brackets, any
  75. variables used in that equation must all be Integer variables - even if
  76. the variable itself is a string. This is true for variables on the left of
  77. the equals, and the right.
  78.  
  79. Points 3 and 4 might seem to contradict each other. So this example should
  80. help:-
  81.  
  82. LET Room$(Store%(3))="The holographic scenery depicts a desert, far and
  83. wide. It is very hot."
  84.  
  85. The variable Room$( ) is a string variable, but in the brackets should be
  86. a number, so an integer variable is used. This is correct. Equally correct
  87. would be:-
  88.  
  89. LET Room$(Store%(3))=Room$(Store%(3))+" It is very hot."
  90. ---------------------------------------------------------------------------
  91.  
  92. :text - this marks a label, which is used by the GOTO command.
  93.  
  94. eg: :start - if the command 'GOTO start' is encountered execution will
  95. jump  to the line following ':start'
  96. ---------------------------------------------------------------------------
  97.  
  98. GOTO text - this jumps to the label 'text'
  99.  
  100. eg: GOTO start - see above.
  101. ---------------------------------------------------------------------------
  102.  
  103. CLS - this command clears the screen.
  104. ---------------------------------------------------------------------------
  105.  
  106. LOOK - this command displays the current location, including exits and 
  107. objects visible to the player.
  108. ---------------------------------------------------------------------------
  109.  
  110. INPUT - this tells Trellis to prompt the player for a command.
  111. ---------------------------------------------------------------------------
  112.  
  113. COMMAND - this command tells Trellis to try and act on the players
  114. command.  Please note that if Trellis will need help carrying out the
  115. command, this  must be done before 'COMMAND' is reached.
  116.  
  117. Commands which can normally be dealt with by Trellis are: GET, DROP, INV,
  118. EXAMINE, LOOK, QUIT and the direction commands. However, you may wish to
  119. 'intercept' these commands and act on them yourself in some cases. For
  120. example, when creating Doors, which are explained elsewhere.
  121. ---------------------------------------------------------------------------
  122.  
  123. RESTART - this command will stop the game and ask the player if he/she
  124. wants  to start again. If Y is pressed the TScript program will be started
  125. again  from the top. If not, control returns to the desktop.
  126. ---------------------------------------------------------------------------
  127.  
  128. QUIT - this command asks the player if he/she is sure about quitting the
  129. game.  If Y is pressed, control is passed to the RESTART command (see
  130. above). If N  is pressed the game continues as if nothing happened.
  131. ---------------------------------------------------------------------------
  132.  
  133. IF condition THEN - this command is quite complicated. It has two forms, a 
  134. single line or block. In both cases the condition is evaluated to be
  135. either  TRUE or FALSE, and determines if the rest of the line (or the
  136. block) will be  executed.
  137.  
  138. The single line version takes this form:-
  139.  
  140. IF condition THEN command - where 'condition' is the condition to evaluate 
  141. and 'command' is the command to execute if the condition is found to be
  142. true.
  143.  
  144. IF Store%(3)=42 THEN PRINT"It is very cold here."
  145.  
  146. Note: the command can't be a label (:) since the label will always be
  147. found  regardless of the condition.
  148.  
  149. The block version takes this form:-
  150.  
  151. IF condition THEN
  152.  commands 1
  153. END IF
  154.  
  155. or this form:-
  156.  
  157. IF condition THEN
  158.  commands 1
  159. ELSE
  160.  commands 2
  161. END IF
  162.  
  163. If the condition is true, in both cases the block of program designated by
  164. 'commands 1' is executed followed by the commands that come after the 'END
  165. IF'. If the condition is false, in the first case program execution jumps
  166. to the command after the END IF and in the second case after the ELSE (ie:
  167. commands 2).
  168.  
  169. The conditions you can use are similar in structure to the equations that
  170. can be used with the LET command, just a little more complex. You can use
  171.  IF Variable=Equation THEN
  172. which is very similar to the LET statement. In the case of IF, however,
  173. this is more correctly described as:-
  174.  IF Equation 1 Comparison Equation 2 THEN
  175. The equals sign can be replaced by a number of 'Comparisons' which are as
  176. follows:-
  177.    =    check if equation 1 equals equation 2
  178.    >    check if equation 1 is higher than equation 2
  179.    <    check if equation 1 is lower than equation 2
  180.    >=   check if equation 1 is higher than or equal to equation 2
  181.    <=   check if equation 1 is less than or equal to equation 2
  182.    <>   check if equation 1 is not equal to equation 2
  183.  
  184. You can also have more than one condition in an IF ... THEN line by using
  185. AND and OR. For example:-
  186.  IF Store%(3)=10 AND Location%(6)=0 THEN
  187.  
  188. The basic rules for the equations used in IF ... THEN statements are the
  189. same as those described above for LET.
  190.  
  191. With conditions, another variable is available for your use. You can't
  192. change what it contains, but you can check it. The variable is called
  193. Moved% and contains either 0 (FALSE) or TRUE (-1). If the last command the
  194. player entered was a direction, and Trellis moved the player as a result,
  195. Moved% will contain -1. If the player wasn't moved by Trellis, Moved% will
  196. contain 0. 
  197.  
  198. Therefore you can find out if the player has moved with the simple IF
  199. statement:-
  200.  IF Moved% THEN
  201.  
  202. This can, of course, be combined with other conditions:-
  203.  IF Moved% AND North%(12)=22 THEN
  204.  
  205. You also have a special function available in conditions. This is called
  206. FNSaid and it is used to find out if the player entered a word defined in
  207. the words file, or one defined already by Trellis. The function returns
  208. either 0 if the word wasn't entered, or -1 if it was. To use it, you put
  209. the appropriate keyword inside speech marks and brackets straight after
  210. the FNSaid:-
  211.  IF FNSaid("SWORD") THEN
  212.  
  213. Again, you can combine this with other conditions using AND/OR. For
  214. example:-
  215.  IF FNSaid("READ") AND FNSaid("TEXT") THEN
  216.  
  217. Note: The IF block structure is very limited. Firstly, it can't be nested. 
  218. This means you can't have an IF block inside another IF block, like this:-
  219.  
  220. IF Store%(3)=14 THEN
  221.  PRINT"This room is very dark. "
  222.  IF Store%(42)=1 THEN
  223.   PRINT" You can hear a ghostly wail."
  224.  END IF
  225. END IF
  226.  
  227. You can, however, put single line IFs inside an IF block. So the above
  228. would  become:-
  229.  
  230. IF Store%(3)=14 THEN
  231.  PRINT"This room is very dark." 
  232.  IF Store%(42)=1 THEN PRINT" You can hear a ghostly wail."
  233. END IF
  234.  
  235. This example was quite straightforward to correct. There will, however, be 
  236. cases when the 'inner' IFs will need more than one line, making an IF
  237. block  necessary. Since this can't be done, you must use an IF with a
  238. GOTO, to jump  to the relevant block of code.
  239.  
  240. This brings to light a further problem. If you use a GOTO within an IF
  241. block,  you must jump OUTSIDE the block. The following code will not work
  242. properly:-
  243.  
  244. IF Store%(3)=14 THEN
  245.  IF Store%(27)<>0 THEN GOTO nextbit
  246.   PRINT"Do this."'
  247.   PRINT"Do something else."'
  248.   PRINT"But only if store 27 contains zero."' 
  249.  :nextbit
  250.  PRINT"Do this every time the player is in room 14."
  251. END IF
  252.  
  253. Having encountered a GOTO, Trellis will think it is no longer inside an IF 
  254. block and report an error when it encounters END IF. This, however, would 
  255. work:-
  256.  
  257. IF Store%(3)=14 THEN
  258.  IF Store%(27)<>0 THEN GOTO nextbit
  259.  PRINT"Do this."'
  260.  PRINT"Do something else."'
  261.  PRINT"But only if store 27 contains zero."' 
  262. END IF
  263. :nextbit
  264. IF Store%(3)=14 THEN PRINT"Do this every time the player is in room 14."
  265.  
  266. This may, at first, seem strange - the GOTO command shouldn't have any
  267. effect on the status of the conditional block. However, it was done for a
  268. reason: If it didn't affect the block you would not be able to jump out of
  269. it because, if you did, the program wouldn't be able to enter another IF
  270. block - an error would occur. This would be very restrictive and,
  271. considering there is already a limitation in the form of no nesting of
  272. these blocks, writing adventures would be very difficult.
  273. ---------------------------------------------------------------------------
  274.  
  275. GET object - this command will make the player pick up the specified
  276. object,  if possible (if it is available, and light enough to carry).
  277.  
  278. eg: GET SWORD - if the sword is available and not too heavy it will be
  279. picked  up.
  280.  
  281. Note: unless you are forcing the player to pick up an object, perhaps as a
  282. result of a puzzle being solved ('You say the magic word and a sword
  283. magically appears in your hand.'), you would probably not use this
  284. command. (If the player enters GET it can be dealt with automatically)
  285. ---------------------------------------------------------------------------
  286.  
  287. DROP object - this drops an object if it is being carried, leaving it in
  288. the  current location. It has the same format as GET, and the same note
  289. applies.
  290. ---------------------------------------------------------------------------
  291.  
  292. PRINT list - this command will print the 'list' on the screen. The list
  293. can  contain a variety of items, as follows:-
  294.  
  295. text, enclosed in speech marks (""). Everything between them will appear
  296. on  the screen. eg: PRINT "This is text enclosed in speech marks and will
  297. appear on the  screen."
  298.  
  299. [equation], where equation will result in an integer number. The number
  300. will be displayed. eg: PRINT [Store%(21)] - will print the contents of
  301. store 21.
  302.  
  303. ' - the computer will print a carriage return and line feed. (The next
  304. thing  to appear will be at the left of the next line.
  305.  
  306. Any or all of the above can be combined in the PRINT command.
  307.  
  308. eg: PRINT'"This will be printed on one line,"'''"and this three lines
  309. below."
  310.  
  311. eg: PRINT'"You are in room "[Store%(3)]"."'
  312.  
  313. eg: PRINT'"The total weight you are carrying is "[Store%(2)]"."
  314.  
  315. The ' parameter is very useful for missing lines, as can be seen with the 
  316. first of the three examples above, but is also useful for another reason:-
  317.  
  318. Many of the commands that automatically put information on the screen do
  319. not output a carriage return themselves, so anything else displayed will
  320. continue  on immediately from them. This is done so that additional data
  321. can be added  by the player, so overcoming limits in line lengths.
  322.  
  323. When you have added the  appropriate text with the PRINT command, use a
  324. single PRINT' (or add the ' to  the end of your PRINT line) to start a
  325. fresh line.
  326.  
  327. You will probably find that sometimes you are starting new lines when you
  328. don't want to, and not starting them when you do. It is easier to use the
  329. first method given above (PRINT') since you can just use this once after
  330. ALL the additional data is displayed.
  331.  
  332. For example. If the description for room 13 was 'You are on a dark forest 
  333. path.' and you wanted to add, via the script file, 'The sunlight shines 
  334. through the gaps in the trees above, making the damp cobwebs sparkle and 
  335. shimmer as they blow in the breeze.' You would add it, somewhere after the 
  336. LOOK command, like this:-
  337.  
  338. IF AT 13 THEN PRINT " The sunlight shines through the gaps in the trees 
  339. above, making the damp cobwebs sparkle and shimmer as they blow in the 
  340. breeze."
  341.  
  342. and, after all the similar commands to do the same for other rooms, use:-
  343.  
  344. PRINT'
  345.  
  346. After this has been displayed, the description for the location will be 
  347. complete, and the carriage return can be output. Hence the PRINT' The
  348. final description that might appear on the screen for this location, then,
  349. night be:-
  350.  
  351. You are on a dark forest path. Exits lead North and South. You can see a
  352. tree  stump. The sunlight shines through the gaps in the trees above,
  353. making the  damp cobwebs sparkle and shimmer as they blow in the breeze.
  354. ---------------------------------------------------------------------------
  355.  
  356. REM anything - this command and everything on the line following it is 
  357. ignored. It can therefore be used for comments. Blank lines are also
  358. ignored - these can be used to space out the script.
  359. ---------------------------------------------------------------------------
  360.  
  361. SPACE list - this command waits for the player to press the space key.
  362. 'list'  is printed to the screen first - it has the same format/structure
  363. as  PRINTĀ list (see above).
  364. ---------------------------------------------------------------------------
  365.  
  366. INV - displays a list of what the player is carrying.
  367. ---------------------------------------------------------------------------
  368.  
  369. EXAMINE object - this displays the more detailed description of an object.
  370.  
  371. eg: EXAMINE SWORD - this would give a more detailed description of the
  372. sword  (if such a description has been included in the objects file.)
  373. ---------------------------------------------------------------------------
  374.  
  375. Please note that certain commands would not normally be needed, since the 
  376. COMMAND instruction would normally deal with them automatically. These 
  377. commands are: LOOK, GET, DROP, INV and EXAMINE. They have been included as
  378. available commands because there may be times when you would want to deal  
  379. with their operations manually. For example, you may decide to always list 
  380. the objects a player has as part of your HELP facility:-
  381.  
  382. IF ENTERED HELP THEN
  383.  PRINT'
  384.  INV
  385.  PRINT'
  386.  REM rest of help code here...
  387.  GOTO what_next
  388. END IF
  389. ---------------------------------------------------------------------------
  390.  
  391. "It's all very well knowing how each of the commands work," I hear you
  392. cry, "but how do they fit together to make a TScript program. I think we
  393. should be told."
  394.  
  395. Okay - but this is not going to be very deep, just a general overview,
  396. maybe with some hints thrown in for good measure.
  397.  
  398. Think of your TScript program in sections. Simplistically, these are:-
  399.  
  400.  1: Initialisation
  401.  
  402.     Set the whole thing up. Put starting values in the stores you are
  403.     going to use, and put the player in the first location.
  404.  
  405.  2: Describe Location
  406.     
  407.     This is done by the software. At the simplest level, all this section
  408.     of your TScript program will consist of is a label and the LOOK
  409.     command:-
  410.  
  411.     :movement_loop
  412.      LOOK
  413.  
  414.     However, if you are adding more complex descriptions by way of
  415.     IF/PRINT commands, these will follow the LOOK command in this section.
  416.  
  417.  3: Conditions 1
  418.  
  419.     These are 'Priority 1 status red emergency conditions' in that they
  420.     will check for important things, such as whether the player has done
  421.     something that means he/she has won (or died) - such as reached a
  422.     certain location. Obviously, that location needs to be described
  423.     first, which is why these are located after the Description section.
  424.     In the event of winning/dying appropriate text must be displayed, and
  425.     the program must either end or start again. (ie RESTART). GOTOs can be
  426.     used to put the routines to do what is necessary in sections 9 or 10
  427.     (see below).
  428.  
  429.     This section could also be used for checking for changes in a
  430.     location, such as a door closing, or a roof collapsing - but these
  431.     could just as easily be part of the section above.
  432.  
  433.  4: Player Input
  434.  
  435.     This is done by the software. It should generally look something like
  436.     this:-
  437.  
  438.     :input_loop
  439.      INPUT
  440.      IF ENTERED QUIT THEN
  441.       QUIT
  442.       GOTO input_loop
  443.      END IF
  444.  
  445.     The reason for the IF structure is to ensure the software correctly
  446.     handles the QUIT command if the player has entered it. If so, the
  447.     software will enter the IF block, prompting if the player is sure. If
  448.     N is pressed, control returns to TScript and the GOTO command will
  449.     jump back to the prompt for player input. (If Y is pressed the
  450.     software will automatically deal with restarting the game or
  451.     returning to RISCĀ OS.)
  452.  
  453.     In a slightly more complex version, you may have one or two more
  454.     conditions that need to be checked as part of the input loop, but
  455.     before anything is actually entered by the player. If so, they would
  456.     be included after the label/before INPUT.
  457.  
  458.  5: Conditions 2
  459.  
  460.     These are 'Priority 2 status not very urgent (but still quite
  461.     important) conditions.' in that they more or less deal with the
  462.     player's input in cases where the software either can't deal with it,
  463.     or might need help.
  464.  
  465.     For example, the player might want to drop an object in a certain
  466.     place, rather than just 'in the room' - eg. a pen onto a desk.
  467.  
  468.     Also, if you know that certain commands can be dealt with
  469.     automatically, with no intervention from your script (see the section
  470.     on speed for a more detailed explanation of this) you can check for
  471.     them at the start of this section and jump to the next section,
  472.     straight past all the other conditions.
  473.  
  474.  6: Act on Player Input
  475.  
  476.     Once all the commands that your program needs to handle have been
  477.     dealt with in the section above, the software can deal with the
  478.     remainder. This section would consist of little more than a label and
  479.     COMMAND:-
  480.  
  481.     :do_command
  482.     COMMAND
  483.  
  484.     If the command can be carried out by Trellis, it will be, otherwise an
  485.     appropriate error message will be displayed.
  486.  
  487.  8: Loop.
  488.  
  489.     This section should do one of two things. If the player has moved
  490.     (that is, his/her location has changed as a result of the last command
  491.     that was entered) it should jump to section 2, above. If not, it
  492.     should jump to section 4. The script to do this, using the labels
  493.     given above, is:-
  494.  
  495.  
  496.     IF Moved% THEN
  497.      GOTO movement_loop
  498.     ELSE
  499.      GOTO input_loop
  500.     END IF
  501.  
  502.     This could be simplified to two lines by not using the IF/END IF
  503.     structure:-
  504.  
  505.     IF Moved% THEN GOTO movement_loop
  506.     GOTO input_loop
  507.  
  508.  9: Return Control To RISC OS
  509.  
  510.     When a game ends the player should be asked if he/she wants to play
  511.     again. If so the game should restart, if not control should return to
  512.     RISC OS. Most of the work in this can be handled by Trellis.
  513.  
  514.     As a part of section 3 of your program you would have told the player
  515.     if he/she has won, died or whatever. These should be followed by a
  516.     jump to this section of the script with 'GOTO game_end' This section
  517.     will then contain the following two lines:-
  518.  
  519.     :game_ends
  520.     RESTART
  521.  
  522. 10: Routines
  523.  
  524.     In some TScript programs you may find it suitable to put whole
  525.     sections of your script here. This would make the sections above look
  526.     somewhat less messy, though the overall picture would be much messier
  527.     since it could increase the number of GOTOs.
  528.  
  529.     Do not mistake this for the concept of subroutines. Each and every
  530.     section of program here would need a GOTO command to take control back
  531.     into the main sections of the TScript file. Therefore, only one point
  532.     in the main file can be accessed from each routine here, so such
  533.     routines can only be called from immediately before that point.
  534.  
  535.     This should only be done to make the higher sections look tidier and
  536.     easier to follow.
  537.  
  538. The above should be considered nothing more than a guideline. Depending on
  539. the game you write, you might drop entire sections from the above, or add
  540. others of your own devising. Indeed, if you look at the script files for
  541. the example games, you will see that they don't fit the sections described
  542. above 100% - there are no hard and fast rules about this. When you are
  543. more experienced you might prefer to do things a little differently, and
  544. that's fine.
  545.  
  546.  
  547.  
  548.