home *** CD-ROM | disk | FTP | other *** search
/ 1,000 Games / Disc1.iso / ARCADE / REXDEMO / REXPP.TXT < prev    next >
Text File  |  1995-11-02  |  25KB  |  785 lines

  1. Rex++ Language System Programming Reference
  2.  
  3.  
  4. Introduction
  5.  
  6. Welcome to the Rex++ Programming System complete with an easy to use integrated development environment (IDE). Rex++ is a programming language that is similar to the high level programming language BASIC (Beginners all-purpose Symbolic Instruction Code). You edit and run your programs using the built-in source code editor/interpreter all from within from the IDE.
  7.  
  8. Rex++ IDE
  9.  
  10. You start Rex++ by typing REX++ followed by the Enter key at the command prompt inside the Rex Blade Virtual Computer Interface (of course you will need a password!)
  11.  
  12. After the program loads you will see a screen that has four basic parts. The very top line is the editor status line. This line displays the current line and column positions of the text as you type as well as the name of the file you are editing. Also displayed is the current edit mode. In Insert mode, text is moved over to the right as you type and in Overstrike mode, text is  written over at the current cursor position.
  13.  
  14. The second area of the screen is the text edit window. In this area you can enter text as you would with any editor. About 16 pages of source code and can be entered with a line width of 50 characters per line. To end a line simply press the Enter key. Below is a summary of the commands supported by the Rex++ Code Editor:
  15.  
  16. Cursor movement commands:
  17.  
  18. Character left                        [LEFT]
  19. Character right                    [RIGHT]
  20. Word left                                [Ctrl+LEFT]
  21. Word right                            [Ctrl+RIGHT]
  22. Line up                                    [UP]
  23. Line down                            [DOWN]
  24. Beginning of line                Home
  25. End of line                            End
  26.  
  27. Insert and delete commands:
  28.  
  29. Delete character                    Del
  30. Delete character to left        Backspace
  31. Delete line                            Ctrl+Y
  32. Insert mode on/off                Ins
  33.  
  34. The third area of the screen is the message status line. Any informative messages displayed by the program will be shown on this line.
  35.  
  36.  
  37.  
  38. The last area of the screen is the command line. Below is a summary of the available commands:
  39.  
  40. command line options:
  41.  
  42. F2    Loads a source file from disk. A list of all the Rex++ programs in the current sub directory is                            displayed in a pick list. Use the arrow keys to highlight the file and Enter to select it.
  43. F3    Saves the current source file to disk.
  44. F4    Runs the current source file in the editor window.
  45. F5    Clears the current source file in the editor window.
  46. F6    Exit Rex++ and returns back to the Virtual Computer Interface of Rex Blade.
  47.  
  48.  
  49. Language Guide
  50.  
  51. This section presents the formal definition of the Rex++ language.
  52.  
  53. Statements
  54.  
  55. Rex++ is made of up of a series of statements that describe the actions the program can take. These are examples of statements:
  56.  
  57.         a := b + c;
  58.         Print("this is a test");
  59.         if (x < 2)
  60.             Answer := x * y;
  61.         endif;
  62.  
  63. Simple statements can either assign a value or transfer the running of the program to another statement in the code. The first two examples shown in the examples are simple statements.
  64.  
  65. Structured statements can be compound statements that contain multiple statements, conditional and repetitive statements that control the flow of logic within a program.
  66.  
  67. Expressions
  68.  
  69. Just as a sentence is made up of phrases, so is a Rex++ statement made up of expressions. The phrases of a sentence are made up of words, and the expressions of a statement are composed of elements called factors and operators. Expressions usually compare things or perform arithmetic, logical or boolean operations. Lets look at some examples of expressions:
  70.  
  71.     x + y                                                A simple sum.
  72.  
  73.     Done <> Error                            A NOT-EQUAL comparison.
  74.  
  75.     i <= Width                                    A LESS THAN OR EQUAL comparison.
  76.  
  77.     -n                                                    The opposite of the variable n.
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. Tokens
  95.  
  96. Tokens are the smallest meaningful elements in a Rex++ program. They makeup the factors and operators of expressions. Tokens are special symbols, reserved words, identifiers, labels, numbers and string contestants; they are akin to the words and punctuation of a written human language. These are examples of Rex++ tokens:
  97.  
  98.     (                                                        Left Paren, usually used for grouping.
  99.  
  100.     :=                                                    Assignment operator.
  101.  
  102.     print                                                A language keyword.
  103.  
  104.     ;                                                        The end of line character.
  105.  
  106. Operators
  107.  
  108. Operators are classified as arithmetic operators, logical operators, string operators and relational operators.
  109.  
  110. Table 1.0 below illustrates the types of operands and results for binary and unary arithmetic operations.
  111.  
  112. Table 1.0 - Operators
  113.  
  114.  
  115. Arithmetic operators:
  116. Operator                    Operation                            Operand types                    Result type
  117.         +                            addition                                number type                        number type
  118.  -                            subtraction                        number type                        number type
  119.  *                            multiplication                    number type                        number type
  120. /                            division                                number type                        number type
  121.  
  122.  
  123. Unary arithmetic operations:
  124. Operator                    Operation                            Operand types                    Result type
  125.         +                            sign identity                        number type                        number type
  126.         -                            sign negation                    number type                        number type
  127.                                                                             
  128.  
  129. Boolean operators:
  130. Operator                    Operation                            Operand types                    Result type
  131.     and                            logical and                        Boolean                                Boolean
  132.     or                            logical or                            Boolean                                Boolean
  133.  
  134.  
  135. String operator:
  136. Operator                    Operation                            Operand types                    Result type
  137.         +                            concatenation                    string type                            string type
  138. Rex++ allows the + operator to be used to concatenate two strings operands. The result of the operation S + T, where S and T are of type string. If the resulting string is longer than 255 characters, it's truncated after character 255.
  139.  
  140. Relational operators:
  141. Operator                    Operation                            Operand types                    Result type
  142.         =                            equal                                    number, string types        Boolean
  143.         <>                        not equal                            number, string types        Boolean
  144.         <                            less than                            number, string types        Boolean
  145.         >                            greater than                        number, string types        Boolean
  146.         <=                        less than or equal to        number, string types        Boolean
  147.         >=                        greater  or equal to            number, string types        Boolean
  148.  
  149.  
  150. Variables
  151.  
  152. A variable can hold a value that can change.  Every variable must be a type. A variable's type specifies the set of values the variable can have. Rex++ support two types of variables, numbers and strings. A number can be any integer or real (decimal) number and a string variable can be up to 255 characters.
  153.  
  154. For example, this next program declares that variables x and y are of type number; therefore, the only values x and y can contain are numbers. Rex++ displays error messages if your program tries to assign any other type of value to these variables.
  155.  
  156.     var x: number;        {variables x is type number}
  157.     var y: number;        {variable y is type number}
  158.     
  159.     x := 12;
  160.     y := 10;
  161.     x := x + y;
  162.  
  163. x is assigned the value 12 originally; two statements later it is assigned the a new value, x + y. As you can see, the value of a variable can vary.
  164.  
  165. All variables are declared with the var statement. Variables can be declared anywhere in the program, but they must be declared first before use.
  166.  
  167. Identifiers
  168.  
  169. Identifiers denote constants, types, variables or commands. An identifier can be up to 63 characters and must begin with a letter or an underscore character "_" and can not contain spaces. Letters, digits, and underscore characters are allowed after the first character. Identifiers are not case sensitive.
  170.  
  171. Numbers
  172.  
  173. Ordinary decimal notation is used for numbers that are constants of integer and floating point types. Numbers with decimals or exponents denote floating point-type constants, while other decimal numbers denote integer-type constants; they must be within the range -2,147483 to 2,147483.
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181. Character strings
  182.  
  183. A character string is a sequence of zero or more characters from the extended ASCII character set, written on one line in the program and enclosed by double qoutes. A character string with nothing between the double quotes is a null string. Examples of character strings include:
  184.  
  185.     "Xtreme Games"        { Xtreme Games }
  186.     "This is a test'            { This is a test }
  187.     ""                                    { null string }
  188.     " "                                    { a single space }
  189.  
  190. Comments
  191.  
  192. The following constructs are comments and are ignored by Rex++:
  193.     
  194.     { Any text not containing right brace }
  195.  
  196.  
  197.  
  198. Library reference
  199.  
  200. This section contains detailed descriptions of all the Rex++ procedures and functions with examples.
  201.  
  202. Declaration
  203. Cls (color: number);
  204.  
  205. Purpose
  206.     Clears the screen.
  207.  
  208. Description
  209.     Cls will clear the screen with the specified color value. The color can range for 0 to 255.
  210.  
  211. Example
  212.     Cls(5);
  213.  
  214. Declaration
  215.     Delay ( time: number);
  216.  
  217. Purpose
  218.     Delays program execution.
  219.  
  220. Description
  221.     Delay stops the currently running program for a specified time period is milliseconds. The time can range from 0 to 32768.
  222.  
  223. Example
  224.     var index: number;
  225.     var color: number;
  226.  
  227.     randomize;
  228.  
  229.     loop(index=1 to 10)
  230.         number := rand(1, 256);
  231.         println("number =", number);
  232.         Delay(10); {delay program for ten milliseconds}
  233.     endl;
  234.     
  235.  
  236. Declaration
  237.     End;
  238.  
  239. Purpose
  240.     Ends the currently executing program.
  241.  
  242. Example
  243.     var n: number;
  244.  
  245.     n := 10;
  246.     if (n = 10)
  247.         println("n is 10");
  248.         end; {stop program}
  249.     endl;
  250.     println("Nope, n is not 10");
  251.  
  252.  
  253.  
  254. Description
  255.     End will stop program execution on the line containing End. The command can be used to abort the program based on some condition.
  256.  
  257. Declaration
  258. Endif;
  259.  
  260. Purpose
  261.     End the code black started with a If command
  262.  
  263. Description
  264. When a If command begins execution, all commands between If and Endif will be executed over and over until the If expression becomes true. Endif tells Rex++ where this block of code ends. There must be a Endif for every If and an error will be displayed if they are unbalanced.
  265.  
  266. Example
  267.     var n: number;
  268.  
  269.     n := 20;
  270.  
  271.     if (n=20)
  272.         println("n is equal to 20");
  273.     endif; {ends the if block}
  274.  
  275. Declaration
  276. Endl;
  277.  
  278. Purpose
  279.     End the code block started with a Loop command.
  280.  
  281. Description
  282.     When a loop command begins execution, all commands between Loop and Endl will be executed over and over until the loop expression becomes true. Endl tells Rex++ where this block of code ends. There must be a Endl for every Loop and an error will be displayed if they are unbalanced.
  283.  
  284. Example
  285.     var n: number;
  286.  
  287.     loop(n = 1 to 10)
  288.         println(n);
  289.     endl; {ends the loop statement}
  290.  
  291. Declaration
  292.     Goto $lable
  293.  
  294. Purpose
  295.     Goto will transfer execution of the program to a specific location.
  296.  
  297. Description
  298.     Goto is a control statement that transfers execution of the program to the instruction following a label.  All labels in Rex++ must begin with a $ (dollar) symbol.
  299.  
  300. Example
  301.     var x: number;
  302.  
  303.     x := 1;
  304.  
  305.     if (x = 1)
  306.         println("x is one.");
  307.         if (x < 2)
  308.             goto $less;
  309.     endif;
  310. endif;
  311.  
  312. $less
  313. println("x was less than 2");
  314.  
  315. Declaration
  316. If (expression: Boolean)
  317.  
  318. Purpose
  319.     Selects execution of program based on a condition.
  320.  
  321. Description
  322.     The If command is used to conditionally execute component statements in the program. The If expression must evaluate to True, the commands following the If will execute until Endif is encountered. If the expression produces False, execution starts on the line following the paired Endif. Note: If/Endif must be balanced or a run-error will be displayed.
  323.  
  324.  
  325.  
  326.  
  327. Example
  328.     var n: number;
  329.  
  330.     randomize;
  331. n := rand(1, 10);
  332. if (n < 5)
  333.     println("n is less than 5);
  334. endif;
  335.  
  336. Declaration
  337.     Kbhit: boolean;
  338.  
  339. Purpose
  340.     Checks if a key is pressed.
  341.  
  342. Description
  343.     Kbhit checks to see of a key has been pressed. Kbhit returns a boolean expression of TRUE if a key has been hit and FALSE if not.
  344.  
  345. Example
  346.     if (kbhit)
  347.         println("a key was hit...");
  348.     endif;
  349.  
  350.  
  351. Declaration
  352.     Kbcode(code: number): boolean;
  353.  
  354. Purpose
  355.     Checks if a specific key is pressed.
  356.  
  357.  
  358.  
  359.  
  360. Description
  361.     Kbcode allows you to check if a specific key is pressed. It has the advantage of allowing you to detect multiple keystrokes. Pass to Kbcode, the scan code of the key you are detecting and it will return TRUE if the key is being pressed or FALSE if not.
  362.  
  363. Example
  364.     if (kbcode(1))
  365.         println("the ESC key was pressed.");
  366.     endif;
  367.  
  368.     if (kbcode(72))
  369.         println("the UP arrow was pressed.");
  370.  
  371.  
  372. Declaration
  373. Line(x1:number, y1: number, x2:number, y2: number);
  374.  
  375. Purpose
  376.     The Line command plots a line using the current graphics color that was set with SetColor.
  377.  
  378. Description
  379.     Line can display a line on the screen from coordinates x1,y1 to x2,y2. The x coordinates can range from 0-319 and the y coordinates can range from 0-199. An error is returned if the coordinates are outside these values.
  380.  
  381. Example
  382. var x1: number;
  383. var y1: number;
  384. var x2: number;
  385. var y2: number;
  386. var n: number;
  387.  
  388. randomize;
  389.  
  390. for (n= 1 to 1000)
  391.     x1 := rand(0, 319);
  392.     y1 := rand(0, 199);
  393.     x2 := rand(0, 319);
  394.     y2 := rand(0,199);
  395.     setcolor(rand(1,  255));
  396.     line(x1, y1, x2, y2);
  397. endl;
  398.  
  399. Declaration
  400. Loop(control variable:number  = initial value TO final value: number)
  401.  
  402. Purpose
  403.     Loop specifies certain commands to be executed repeatedly.
  404.  
  405. Description
  406.     The Loop statement causes commands to be repeatedly executed while a progression of values is assigned to a control variable. The control variable must be a number type and already defined. The value of the control variable is incremented by one for each repletion. If initial value is greater or less than final value, the contained commands isn't executed. Commands will executed down to the Endl command. There must be a matching Endl for every loop or and error will be returned.
  407.  
  408. Example
  409.     var n: number;
  410.  
  411.     loop(n = 1 to 10)
  412.         println(n);
  413.     endl;
  414.  
  415. Declaration
  416. Plot(x:number, y: number)
  417.  
  418. Purpose
  419.     Plots a single pixel on the screen using the current color.
  420.  
  421. Description
  422.     Plot will draw a pixel on the screen at the specified coordinate using the color set by the last SetColor command. The x value can range from 0-319 and the y value can range from 0-199. Any values outside these ranges results in a run-time error.
  423.  
  424. Example
  425.     plot(50, 50);
  426.     plot(160, 100);
  427.  
  428. Declaration
  429. Print(expression:number|string|string constant)
  430.  
  431. Purpose
  432.     Outputs data to the screen with no line feed.
  433.  
  434. Description
  435.     Print can display a number, string and string constant (text between double quotes). Print does not move the cursor to the next line. Print will use the color set by the last call to SetColor and will be printed at the current cursor position.
  436.  
  437. Example
  438.     var n: number;
  439.     var s: string;
  440.  
  441.     n := 100;
  442.     s := "Jarrod Davis"
  443.     print("This is a test");
  444.     print(n);
  445.     print(s);
  446.     print(n => 100); {will display TRUE}
  447.     print(n = 1); {will display FALSE}
  448.  
  449.  
  450. Declaration
  451. PrintLn;
  452.  
  453. Purpose
  454.     Outputs data to screen with line feed.
  455.  
  456. Declaration
  457.     Same as Print but performs a line feed and move the cursor to the beginning of the next line.
  458.  
  459. Declaration
  460. Rand(min: number, max: number)
  461.  
  462. Example
  463.     See Print example.
  464.  
  465. Purpose
  466.     Returns a random number between min and max.
  467.  
  468. Description
  469.     Rand can be used to get a random number between minimum range (0) and maximum range (32767). Any values outside these ranges results in a run-time error..
  470.  
  471. Example
  472.     var n: number;
  473.     randomize;
  474.  
  475.     n := rand(0, 10);
  476.     println(n);
  477.  
  478. Declaration
  479. Randomize;
  480.  
  481. Purpose
  482.     Seeds the random generator.
  483.  
  484. Description
  485.     Randomize initializes the random generator. This statement must be called be using Rand.
  486.  
  487. Declaration
  488. SetColor(color: number);
  489.  
  490. Purpose
  491.     Set a new color value.
  492.  
  493. Description
  494.     SetColor specifies a new color value that is used by all of the graphic routines that draws to the screen. The color value can range between 0 and 255. Any values outside this range will result in a run-time error.
  495.  
  496. Example
  497.     SetColor(50);
  498.  
  499. Declaration
  500. SetCursor(x: number, y: number);
  501.  
  502. Purpose
  503.     Sets the current cursor position.
  504.  
  505. Description
  506.     SetCursor sets the new graphics cursor position. The x coordinate can range from 0 to 319 and the y coordinate can range from 0 to 199. Any values outside the ranges will result in a run-time error.
  507.  
  508. Example
  509.     SetCursor(50, 50);
  510.  
  511. Declaration
  512. To
  513.  
  514. Purpose
  515.     Used only in the Loop command when specifying the initial and final values.
  516.  
  517. Description
  518.     To must be used to separate the initial and final values in the Loop command. A run-time error is returned is it is not found.
  519.  
  520.  
  521. Example
  522.     var x: number;
  523.  
  524.     loop(x = 1 TO 100);
  525.         ...
  526.     endl;
  527.  
  528. Declaration
  529. Var
  530. Purpose
  531.     Declares a variable.
  532.  
  533. Description
  534.     Var is used to declare a variable. Rex++ uses two types of variables, a number and a string. Variables have to be declared before used or a run-timer error will result.
  535.  
  536. Example
  537.     var n: number;
  538.     var s: string;
  539.  
  540.     n := 1;
  541.     s := "test";
  542.  
  543.     println(n);
  544.     println(s);
  545.  
  546. Declaration
  547. WhereX;
  548.  
  549. Purpose
  550.     Returns the current X coordinate of the graphics cursor.
  551.  
  552. Description
  553.     WhereX is a function that returns the current horizontal position of the graphics cursor. It will return a value in the range of 0 to 319.
  554.  
  555. Example
  556.     println(wherex);
  557.  
  558. Declaration
  559. WhereY
  560.  
  561. Purpose
  562.     Returns the current Y coordinate of the graphics cursor.
  563.  
  564. Description
  565.     WhereY is a function that returns the current vertical position of the graphics cursor. It will return a value in the range of 0 to 199.
  566.  
  567. Example
  568.     println(wherey);
  569.  
  570.  
  571. Examples
  572.  
  573. This section contains listings for a number of example programs that demonstrates the various features of the Rex++ language. All of these programs will be installed on your hard drive along with Rex Blade, so you don't have type them in. To load any of them, simply note their name(s) and use the LOAD command from the IDE.
  574.  
  575. The first example shown below in Listing 1.0 illustrates the use of the random number generator coupled with the clear screen function. The program begins by declaring a loop variable followed by seeding the random number generator. The program then enters the main loop which iteratively clears the screen with a new random color each cycle.
  576.  
  577. Listing 1.0 - CLS.RPP
  578.  
  579. { This program demonstrates the cls command }
  580.  
  581. var x: number;                                     { declare x as a number }
  582.  
  583. randomize;                                                { initialize random number generator }
  584.  
  585. loop(x=1 to 50)                                    { setup to loop from 1 to 50 }
  586.   cls(rand(0, 255));                        { clear the screen with a random color }
  587.   delay(50);                                            { pause program execution for 50 milliseconds }
  588. endl                                                            { end the loop }
  589.  
  590. The next example program shown below in Listing 2.0 illustrates how to use the cursor setting and querying functions. The program sets the position of the cursor and then retrieves it with the "where" functions. This is a good example of how to track your text output for formatting.
  591.  
  592. Listing 2.0 - CURSOR.RPP
  593.  
  594. { This program demonstrates the setcursor command }
  595.  
  596. var x: number;                                        { declare x as a number }
  597. var y: number;                                        { declare y as a number }
  598.  
  599. setcursor(50, 80);                            { set graphics cursor to position 50,80 }
  600.  
  601. println("");                                            { print a blank line }
  602. print("X = ",wherex);                        { print value of current horizontal position }
  603. print("Y = ",wherey);                        { print value of current vertical position }
  604.  
  605. All computer languages allow complex expressions to be evaluated, however, Rex++ goes a little farther in some areas such as string processing. Listing 3.0 below shows both numeric and string data types benig defined and output. Notice the use of the addition operator to concatenate strings together, this is a very powerful language construct.
  606.  
  607. Listing 3.0 - EXPR.RPP
  608.  
  609. { This program demonstrates expressions and strings }
  610.  
  611. var s: string;                                        { declare x as a string }
  612. var n: number;                                        { declare n as a number }
  613.  
  614. n := 100 + 100;                                    { assign n a number value }
  615. s := "This is a test" + " this is another test "; { assign s a string value }
  616. println(s);                                            { print value of s }
  617. println(n);                                            { print value of n }
  618. println("I am the " + "Man!");    { print a string expression }
  619. println( ((4*5) / 2) + (100/2)); { print a number expression }
  620.  
  621. The next example below, Listing 4.0 is our first program that does something a bit graphical. The program begins by declaring a number of working variables, the program then enters into a main loop and repeatedly computes a set of random numbers. These numbers are used as parameters to the color and line drawing functions. The result, a collection of random lines drawn on the screen in random colors.  
  622.  
  623. Listing 4.0 - LINE.RPP
  624.  
  625. { This program demonstrates the line command}
  626.  
  627. randomize;                                                { setup the random number generator }
  628.  
  629. line(0,0,319,199);                            { draw a diagonal line from 0,0 to 319,199 }
  630.  
  631.  
  632. var n: number;                                        { declare n as a number }
  633. var x1: number;                                    { declare x1 as a number }
  634. var y1: number;                                    { declare y1 as a number }
  635. var x2: number;                                    { declare x2 as a number }
  636. var y2: number;                                    { declare y2 as a number }
  637.  
  638. loop(n=1 to 1000)                                { set n to loop from 1 to 1000 }
  639.   x1 := rand(0, 319);                        { assign x1 a random number from 0 to 319 }
  640.   y1 := rand(0, 199);                        { assign y1 a random number from 0 to 199 }
  641.   x2 := rand(0, 319);                        { assign x2 a random number from 0 to 319 }
  642.   y2 := rand(0, 199);                        { assign y2 a random number from 0 to 199 }
  643.   setcolor(rand(1, 255);                { set graphics color a random color from 1 to 255 }
  644.   line(x1, y1, x2, y2);                    { draw line }
  645. endl;                                                            { end loop }
  646.  
  647. Listing 5.0 below is similar to Listing 4.0 except that instead drawing random line segments, random pixels are drawn. However, don't be fooled by the example's simplicity since there is a more important language construct to be learned here. Notice that instead of using local variables to hold random data values, the random pixel postions are computed as parameters to the plot function. Hence, you may use this technique freely to save a local variable(s).
  648.  
  649. Listing 5.0 - PLOT.RPP
  650.  
  651. { This program demonstrates the plot command }
  652.  
  653. var x: number;                                     {declare x as a number}
  654.  
  655. randomize;                                         {seed random number generator}
  656.  
  657. loop(x=1 to 10000)                            { set x to loop from 1 to 1000 }
  658.   setcolor(rand(1, 255));                { set graphics color a random number from 1 to 255 }
  659.   plot(rand(0, maxx), rand(0, maxy));    { plot pixel at random x,y position }
  660. endl;                                                            { end loop }
  661.  
  662. println("I am the man!");                { print a string expression }
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680. No language would be complete without the ability to create text output. Rex++ has two functions to accomplish this task: print() and println(). Listing 6.0 below shows an example use of both of these functions, notice that the functions can take either numeric or string data.
  681.  
  682. Listing 6.0 - PRINT.RPP
  683.  
  684. { This program demonstrates the print/println commands}
  685.  
  686. var x:number;                                        { declare x as a number }
  687. var y:string;                                        { declare y as a string }
  688.  
  689. loop(x=1 to 10)                                    { setup x to loop from 1 to 10 }
  690.  println("number: ", x);                { print value of x }
  691. endl;                                                            { end loop }
  692.  
  693. print("this is a test");                { print string constant with no line feed}
  694. println(" this is on the same line.");    { print string constant with line feed }
  695. println("but this is not.");        { print string constant with line feed }
  696.  
  697. Listing 7.0 is a formal example of using the random functions, not too exciting!
  698.  
  699. Listing 7.0 - RAND.RPP
  700.  
  701. { This program demonstrates the randomize/rand commands}
  702.  
  703. randomize;                                                { setup random number generator }
  704.  
  705. var n: number;                                        { declare n as a number }
  706.  
  707. loop(n=1 to 20)                                    { set n to loop from 1 to 20 }
  708.   println(rand(1, 1000));                { print a random number between 1 and a 1000 }
  709. endl;                                                            { end loop }
  710.  
  711.  
  712. Listing 8.0 below illustrates the use of the real-time keyboard I/O functions which allow you to not only detect if a key has been pressed, but if multiple keys have been pressed. This particular example shows how to track the arrow keys.
  713.  
  714. Listing 8.0 - KEYTEST.RPP
  715.  
  716. { This program demonstrates the kbcode function and the goto command }
  717.  
  718. println("Press the arrow keys, <ESC> to quit...");               { tell what to do }
  719.  
  720. setcolor(14);                                                                                                        { set text color to yellow }
  721.  
  722. $checkkeys                                                                                                                { define a label }
  723.  
  724.   {clear keys}
  725.   setcursor(0,6);
  726.   print("           ");
  727.   setcursor(0,12);
  728.   print("           ");
  729.   setcursor(0,18);
  730.   print("           ");
  731.   setcursor(0,24);
  732.   print("           ");
  733.  
  734.   {check up arrow}
  735.   if (kbcode(72))
  736.     setcursor(0, 6);
  737.     print("up arrow");
  738.   endif;
  739.  
  740.   {check down arrow}
  741.   if (kbcode(80))
  742.    setcursor(0, 12);
  743.    print("down arrow");
  744.   endif; 
  745.  
  746.   {check left arrow}
  747.   if (kbcode(75))
  748.     setcursor(0,18);
  749.     print("left arrow");
  750.   endif;
  751.  
  752.   {check right arrow}
  753.   if (kbcode(77))
  754.     setcursor(0,24);
  755.     print("right arrow");
  756.   endif;
  757.  
  758.  
  759.   {check for <ESC>}
  760.   if (kbcode(1))
  761.     goto $out
  762.   endif;
  763.  
  764. goto $checkkeys
  765.  
  766. $out
  767. println("");
  768. println("out of here");
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778. 13
  779.  
  780.  
  781. 16
  782.  
  783.  
  784.  
  785.