Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index


G

GCOL

Purpose

This statement sets the colour to be used by all subsequent graphics operations. In other words it selects the graphics foreground colour and the graphics background colour. It also specifies how the colour is to be placed on the screen. The colour can be plotted directly, ANDed, ORed or Exclusive-ORed with the colour already there, or the colour there can be inverted.

The first number specifies the mode of action as follows:

0 plot the colour specified

1 OR the specified colour with that already there

2 AND the specified colour with that already there

3 Exclusive-OR the specified colour with that already there

4 invert the colour already there

The second number defines the logical colour to be used in future. If the number is greater than 127 then it defines the graphics background colour. If the number is less than 128 then it defines the graphics foreground colour. See the keyword COLOUR for more information.

Example

100 GCOL 0,2

GCOL 3,129

Description

This statement is used to select the logical colours used by graphics statements.

Syntax

GCOL <numeric>,<numeric>

Associated keywords

CLS, CLG, MODE, COLOUR, PLOT

GET

Purpose

This function waits for a key to be pressed on the keyboard and then returns with the ASCII number of the key pressed. See page 64 for a description of ASCII numbers.

The GET function is used whenever the computer needs to wait for a reply from the user before continuing.

Note that when using GET the character typed on the keyboard will not appear on the screen. If you wish it to appear you must then ask the computer to print it.

Examples

1040 keyhit=GET

350 X=GET

Description

A function which waits for the next character from the input stream. The function then returns the ASCII value of the character.

Syntax

<num-var>=GET

Associated keywords

GET$, INKEY, INKEY$

GET$

Purpose

The GET$ function waits for a key to be pressed on the keyboard and then returns with a string containing the character pressed. See the previous keyword GET for a similar function and for further explanation.

For example, at the end of a game program you may wish the computer to ask the player whether or not he wants another go. The demonstration program below shows how this can be done.

Note that when using GET$ the character typed on the keyboard will not appear on the screen. If you wish it to appear you must then ask the computer to print it.

Examples

1050 A$=GET$

Syntax

<string-var>=GET$

Associated keywords

GET, INKEY, INKEY$

Demonstration Program

2100 PRINT "Do you want to play another game";

2120 REM if user presses Y then

2130 REM go to line 100

2140 IF GET$="Y" THEN GOTO 100

2160 REM if it gets this far then the

2170 REM reply was not "Y" so give up!

2180 STOP

GOSUB go to a subroutine

Purpose

Quite often a group of lines in a program needs to be used in a number of different places within the main program. Instead of repeating the same piece of program several times one can separate out a small sub-section into a subroutine. This subroutine can then be "called" from a number of different places in the main program by means of the statement GOSUB. The end of a subroutine is indicated by the word RETURN.

This causes the program to return to the statement after the GOSUB statement.

Beware of a subroutine calling itself too many times: "a depth" of 26 subroutines is the maximum that is allowed.

As with GOTO, it is possible to GOSUB to a calculated line number. The same cautions that apply to GOTO apply to GOSUB in this case.

Example

1020 GOSUB 4000

Description

A statement used to call a section of program as a subroutine. One subroutine may call another subroutine (or itself) up to a maximum nested depth of 26.

Syntax

GOSUB <numeric>

Associated keywords

RETURN, ON

Demonstration Program

First, here is a program to print out random phrases without using a subroutine

100 REM A$ contains 7 words and each word

105 REM contains 5 characters - letters or spaces

110 A$="hand mouthear leg arm chest elbow"

120 FOR count=l TO 10

125 REM pick a random number

130 R=RND (7)

140 REM and use it to pick a random word

150 B$=MID$(A$,5*R-4,5)

160 REM print a message

170 PRINT "My ";B$;" hurts"

180 REM get another random word

190 R=RND(7)

200 B$=MID$(A$,5*R-4,5)

210 REM and print out a second message

220 PRINT "Is your ";B$;" alright?"

230 NEXT count

Now look at the same program using a subroutine and with the REMs (remarks) removed.

110 A$="hand mouthear leg arm chest elbow"

120 FOR count=1 TO 10

150 GOSUB 810

170 PRINT "My ";B$" hurts"

190 GOSUB 810

220 PRINT "Is your ";B$ " alright?"

230 NEXT count

240 END

The "7" in line 810 is there to select one of the 7 words in A$. In line 810 both the "5"s are there because each word contains five letters or spaces. It is essential that all the words contain the same number of characters.

Finally, here is the same program written with a string function, with REMs left out and generally tidied up.

110 A$="hand mouthear leg arm chest elbow"

120 FOR count= 1 TO 10

170 PRINT "My ";FNword;" hurts"

220 PRINT "Is your ";FNword;" alright?"

230 NEXT count

240 END

800 DEF FNword= MID$(A$,5*RND(7)-4,5)

GOTO go to a line number

Purpose

This statement makes the computer jump to a specified line number instead of continuing to the next one in the program. It changes the order in which the computer executes a program.

Although GOTO is simple to use, do so with caution! It is all too easy to make a program difficult to follow by using too many GOTOs. Following a program full of GOTOs is like trying to disentangle a plateful of spaghetti and arrange it in a straight line!

Adherents of "structured programming" encourage program writers to use structures like REPEAT...UNTIL and FOR...NEXT and to avoid most(but not all) GOTO statements.

It is possible in this version of BASIC to GOTO a variable. In the following example the destination variable is called "somewhere":

10 somewhere=1005

20 GOTO somewhere

but this feature must be used with great care since, if the program is renumbered using the RENUMBER command, the program will probably then branch to the wrong line.

Note that if the destination line number is to be calculated using a mathematical expression then that expression must be in brackets.

GOTO can be used as a command to start a program without destroying the values assigned to the variables.

Examples

GOTO 330

100 IF X>5 THEN GOTO 2000

100 GOTO (starts*55+14)

Description

A statement used to transfer control to a specified or calculated line number unconditionally.

Syntax

GOTO <numeric>

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001