I've tried searching this forum for the answers, I really have, but I just can't find them:
I've finally gotten around to firing up a card with RISCOS on it - looks nice. Now I want to write, save, load and run a simple BASIC program.
So far, I've only found that if I press F12, I get into a command line, and if I then type BASIC <enter> I get the BASIC system prompt ">". What I do after that is less clear.
I tried the obvious:
Code: Select all
>10 for x = 1 to 20
>20 print "this is great!"
>30 next x
(Am I in immediate mode?)
As others have pointed out BBC BASIC is CASE SENSITIVE (so PRINT and print mean different things the first one is a BASIC keyword - the second a floating point variable name...).
Your code is fine and it would have worked perfectly if UPPER CASE had been used for the BASIC keywords. Just click on the CAPS LOCK to enter the commands in UPPER CASE (variables can be either UPPER or lower - but case must be consistently used and (if all UPPER) should generally not be the same as a BASIC keyword).
SiriusHardware wrote:What would be the actual steps to enter that program, list it on the screen, run it, save it to disc, and load it from disc? And by the way, are the line numbers necessary, or can I just use labels?
Line numbers are necessary IF you're entering them from the command line (as you are). Editors (like !Edit or !StrongEd) "hide" them so you can type the lines without line numbers (they are there but hidden). BBC BASIC only uses LINE NUMBERS (they ARE numeric) rather than LABELS.
Here's a VERY SMALL list of common BASIC keywords that you may find handy:
COMMANDS are things you type WITHOUT a line number, here are a few useful ones:
- Makes the existing program disappear (sort of ... I'll explain in a minute...). You should type NEW before starting a NEW program but only if you've saved the previous one FIRST.
- Usually reverses NEW - so long as you haven't started on a new program yet.
- well it Automatically puts line numbers in for you AS YOU TYPE. It (by default) leaves a space of 10 between each line number. To EXIT the AUTO line numbering press the <ESCAPE> key. Note AUTO 20 Starts at line 20; AUTO 10,5 starts at 10 but goes up in increments of 5.
- Runs your program (surprise that...).
- Renumbers lines (to tidy programs after you've added a few lines less than 10 apart between existing lines). It's also handy if you have no line number gap - as it automatically renumbers things - putting the usual gap of 10 back.
your program just type SAVE "yourfilename" - and it'll save a BASIC file called yourfilename
in the current directory.
A useful trick is to put 10 REM > Yourfilename
at the START of your program then when you type SAVE you can omit the filename and it'll take it from that line (cool or what...). Note the REM > is required (As an aside REM
means a REMARK - a note about the program or comment left for yourself or other coders).
the file just use LOAD followed in quotes with the filename you originally saved (e.g., LOAD "yourfilename").
General Purpose Statements that are handy...
- Clear Screen
- Sets the Colour of TEXT
- Sets the colour of Graphical Elements (G- Graphics and COL for Colour). If you use VDU 5 it also sets the colour of any text you plot like a graphic.
- Gets the Mouse X% and Y% co-ordinate - with B% containing any button pressed.
move to a point X% across and Y% up the screen without drawing (there's also a version of MOVE (MOVE BY) which allows you to move relative to your current position).
- Draws from your current x,y position to X%,Y% (there's also a DRAW BY for relative drawing)
(X,Y and Radius - give you one guess...)
CIRCLE FILL X%,Y%,R%
(rather than an outline the circle with FILLED inside).
Here's one you can try to impress your friends (and your parrot if you have one...):
With the DESKTOP visible just press <F12>
Type BASIC at the "*" command prompt
then enter the following program
When finished type SAVE
to save the program (it's called RECTANGLY)
Code: Select all
10 REM >RECTANGLY
30 MOUSE X%,Y%,B%
40 RECTANGLE X%,Y%,400,500 TO 600,600
50 UNTIL B%<>0
And if I've made no mistakes there that should be nice enough... The REPEAT...UNTIL loop continues UNTIL you press a MOUSE KEY (B% then becomes set to a non-zero value - the UNTIL then becomes TRUE and the loop exits.
Note the X%,Y%,B% are integer variables you could used ones named differently (perhaps more meaningfully like xcoordinate%
). Using Integer variables (ones ending with a "%" is faster than using real/floating point ones). You would, however need floating point ones where fractional results are expected... (x would be a floating point variable (could hold 1.86), x% is an integer one (1) and x$ is one that holds text like "Hello" (x$ is called a string variable
) - all three are independent and distinguishable from each other....)
Variable names in BBC BASIC can be long - and all letters are significant. Case is also important - the variables called xyz% and Xyz% are different
For speed some variables are stored at fixed
memory locations (these are called the resident integers
- single letter integers like (A% to Z%)).
That's a very brisk overview there are many more online resources that can "flesh" things out - if you have any further questions though please just ask here...