home *** CD-ROM | disk | FTP | other *** search
/ APDL Soft Rock Games / APDL_SOFTROCK.iso / trellis / docs / part05 < prev    next >
Encoding:
Text File  |  1999-04-02  |  22.4 KB  |  585 lines

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