STOSSER Issue #2 (May 1993)

Understanding STOS Basic

By Dion Guy
Part 2 of a complete guide to variables

 

This article has been copied in it’s entirety from STOS MAGAZINE thank’s to the kind permission of it’s author DION GUY who retains the copyright to the said article.

 

Here is the second part of our variable explanations, it carries on from where issue 1 left off. Next month will contain the last part of the A-Z of variable commands and also a few more things you should know about STOS variable manipulation. As with last month (var) in the variable and (num
var) represents an integer variable or a real number variable. If you have any queries on the tutorial, don’t forget you can write in to the mag. Use the normal address with the prefix “HELPLINE” and don’t forget to enclose a stamped S.A.E!

FREE

FREE is a reserved variable which holds the amount of free memory space available. Whenever you use it, it also reorganises the memory space used to hold your string variables (this is often refered to as garbage collection) It can be used either as – print free or-a=free.

INC num var

INC is a very simple command which INCreases the num var by 1. Eg (10 A=10:inc A:print A). See DEC.

INKEY$

The format of this command is var=inkey$. Inkey$ is used to read keyboard presses. For example:

10 repeat

20 A$=inkey$

30 until A$<>””

40 print A$:A$=””:goto 10

When you run this program, upon pressing a key the program will display the letter/number you pressed. Note: special keys such as Help, Undo and the cursor keys will not register, you have to use scancode. See SCANCODE.

INPUT num var/var

You use input to ask the computer user for information to be entered. The information is stored in the variable at the end of the line. You use the input like this – input A$ or input “Type something in:”;a$. You can use input with a string or a number variable. If you use input with something between the two speech marks then the computer will display text in between them and then wait for the user to enter something – which will be then be stored in the variable name at the end of the line. If you do use speech marks then you have to put a semi colon(;) after the closing speech mark and before the variable name. If you use it on its own, say – input b$ – then the computer will display a question mark and await keyboard input. The user will have to type in some text – letters or numbers for string inputs but ONLY numbers for number variable inputs – and finish the entry off with [RETURN]. Here is an example use of input:

10 input “What is your name please?”;name$ : rem Enter your name and press [RETURN].

20 Print “Hello “;name$;” I am your computer!” : end

INSTR(var,var)

Instr is used to search for the occurrences of one string inside another. e.g. – [ print instr(“Mary had a little lamb” ,”had”) ]. This will return the position of the first occurrence of “had” in the previous string. In this case it will return 6. If this cannot find an occurrence it would return to the value 0.

INT(num var)

Int is used to convert a floating point number into an INTeger number. In other words it rounds down the decimal value of the specified variable into a whole number. Eg – print int(7.34) will produce 7.

LEFT$(var,num var)

This command returns the left most characters in a string starting from the position held in num var. e.g. print left$(“Hello”,2″ – will display “He”. Alternatively you can change characters in a string with LEFT$. For example:

10 a$=”MOSS”

20 left$(A$,3)=”STO”

30 print a$

When ran this program will display “STOS”. Note that using this variant on left$ you have to use a string variable rather than expression – i.e. left$(A$,3) rather than left$(“MOSS”,3) See RIGHT$ and MID$.

LEN(var)

This simply returns the LENgth of the string(in characters) in brackets. i.e. print len(“HELLO”) – will display 5.

LOWERS(var)

Another simple command. This changes a string variable into all lower case letters. i.e. print lower$(“HELLO) – will display “hello”.

MATCH(num var/var array,num var/var)

Match is only to be used when you have SORTed a array out beforehand – using the SORT command. What match does is find the closest match to the specified variable (held in the variable after the comm) in the array. If the command can find the exact match then it will return a value of 0. If, however, it cannot find an exact match then it will return a negative number. The absolute value of this number will hold the place where the closest match to the specified variable is found. This command in conjunction with SORT, INSTR, LEFT$, MID$, RIGHT$, could form the basis of a powerful adventure game Parser. See SORT.

MAX(num var/var,num var/var)

MAX returns the MAXimum value out of the two specified variables. For e.g. print max(8,2) – will return 8. Likewise – print max(“A”,”B”) – will return B. You cannot mix variables to compare though, i.e. you could not do – print(“A”,2). See MIN.

MIDD$(var,num var,num var)

This command returns the middle characters in a string starting from the position held in the first of the two num vars and ending after the number of the characters held in the second num var. e.g.

10 A$=”STOS Magazine”

20 B$=mid$(A$,6,3)

30 print B$

This short program will display “Mag” which starts 6 characters along and is 3 characters long. As with LEFT$ there is another way of using Mid$. For example:

10 A$=”FAST”

20 mid$(A$,3,2)=”OO”

30 print A$

This will display “FOOT” as you have changed the middle two characters of a$. As with left$ you can only use this method with a string, not an expression. e.g you couldn’t do – mid$(“FAST”,2,2)=”OO”. See LEFT$ and RIGHT$

MIN(var/var,num var/var)

MIN returns the MINimum value from the two specified variables. e.g. print min(“100,23)” – will display 23. See MAX

RIGHT$(var,num var)

Basically the opposite of LEFT$, RIGHT$ returns the rightmost characters of the specified string. e.g. print right$(“Hello”,2) will display “lo”. As with LEFT$ and MID$ you can alter characters in a string using right$. For example:

10 A$=”MOSS”
20 right$(A$,2)=”RE”
30 print A$

This will display “MORE” as the right 2 characters have been changed. As with left$ and mid$ you cannot use an expression with this use of right$. You have to use a string. i.e. – right$(“MOSS”,2)=”RE” – is illegal. See left$ and mid$.

RND(num var)

RND is used to pick a RaNDom number from 0 to the number in the brackets. For example – a=rnd(100) – will pick a random number from 0 to 100 and store it in [a]. RND is an invaluable command as there is no other way to get random numbers. See Understanding STOS Basic in issue 1 for an example number guessing program (fully explained) which makes use of (depends on!) RND.

SCANCODE

SCANCODE is used in unison with inkey$ to read keyboard input. Only using scancode can you read keys like the arrow keys,the help key and the undo key(as they have no ASCII value). Scancode is basically used to hold the number of the last key input with inkey$. e.g.

10 repeat
20 k$=inkey$
30 sc=scancode
40 until k$<>””or sc<>0
50 print “scancode:”;sc
60 print “key pressed:”;k$
70 sc=0:k$=””:clear key:goto 10

Once run, when you press various keys the program will display the scancode and the key you pressed. For example pressing [A] will display “scancode:30” and “Key pressed:A”. However if you press a key with no ASCII value then it will display the scancode but no letter pressed. ie – If you press, say, [undo] then the computer will display “Scancode:97″ and Key pressed:”.See INKEY$.

Pages: 1 2 3 4 5 6 7 8 9

      

About author View all posts Author website

Neil Halliday

Neil started coding in STOS in 1989 just after it was released in the UK.

During those 31 years he has written numerous demo screens, routines, games and extensions, most of which are now lost due to a massive hard disk crash. What remains on floppy disk is still being discovered and posted on the STOS Coders website and stored in the cloud for everybody to enjoy (or laugh at).

Neil is the author of the GBP Extension which added some pretty cool commands to STOS, along with the "Development" extension that enabled enhanced STE functionality, including probably one of the simplest hardware scrolling routines around.

Along with Bruno Azzara, Geoff Harrison and Mike Halliday we had loads of fun back in the day trying to push STOS to it's limits. We are all now enjoying bringing our knowledge to a new generation of STOS Coders.

Leave a Reply

Your email address will not be published. Required fields are marked *