Table of Contents
Introduction to Tiny BASIC Web, version 0.1
©2025 by Mark Damon Hughes
cyberhole.online/basic/
Text licensed as CC BY-NC-SA Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license
Code licensed as BSD, see LICENSE.txt
Tiny BASIC Web (TBW hereafter) is an interpreted, interactive BASIC which can be embedded in a web page. The purpose is to make interactive menus and mini-games easy to deploy. It's not a fully-baked programming environment, and not usable on command-line, both of which exist in many other places.
This is a tutorial for using it.
The current version is Level 1, version 0.5. L1 is a very minimal subset of BASIC, but it's enough to run some non-data-intensive programs.
When you start the page - cyberhole.online/basic/basic.html
You'll get a bootup logo of colored blocks, TinyBasicWeb version number, and a prompt of READY
. You are now at command mode. READY
happens at startup and after time-consuming (network) operations. Most commands or lines entered return you to command mode immediately.
Click on the Spec link on that page, and it'll show all the gory technical details of the language.
Type DIR
(hit Enter after this and any other line I tell you to type), and
you'll see a list of stored programs (actually on the server, not a real
"disk"). LOAD "beer.bas"
will load the "99 Bottles of Beer" program. You can
type LIST
to see what it looks like (the actual listing will be more verbose
and shouty, because it standardizes every command), then RUN
to start it.
Type '9' and it prints the familiar drinking song.
1 CLS
2 INPUT "How many bottles of beer on the wall? ",b
3 LET b=(b%10000)
4 IF (b<1) THEN ?"1 or more beers!"
5 IF (b<1) THEN GOTO 2
10 LET s$="s"
11 IF (b=1) THEN LET s$=""
20 ?b;" bottle";s$;" of beer on the wall, ";
21 ?b;" bottle";s$;" of beer. Take one down, ";
22 ?"pass it around, ";
30 LET b=(b-1)
31 IF (b>0) THEN GOTO 10
40 ?"No more bottles of beer on the wall!"
99 END
b
in this case. Because b
doesn't end in $
, it's numeric, so anything but a number is converted to 0.
%
modulo (remainder after division). All expressions must be wrapped in parentheses.?
) a message, and go back to input if not.$
is a string, it can hold text (up to 255 characters). s$
is being used to hold plurals, and we assume "beers" unless b=1.?
is short for PRINT, which displays text to the screen. ;
puts two items out without space between them, you can also use ,
which has a whole tab column, up to 8 chars. ;
at the end also indicates we don't have a newline, so this text wraps around.For short programs, you can type them in "live", just write the line number and
statements, Enter, and it should silently accept it, or error. RUN
when
you're ready to test it.
I suggest writing longer programs in a local text editor, then pasting them
into TBW (⌘V
or ^V
). It'll probably have errors, and the messages are kind
of awful, but they should tell you where in the line an error occurred. Check
the spec and this intro, and fix it, re-paste just the problem lines.
Write programs in a modular fashion, one part at a time. I usually make major blocks at 100s, minor blocks at 10s, and then increment lines in a block by 1, 2, or 5 at a time. Use GOSUB/RETURN to call subroutines, and keep a comment at the start (or one line before) each subroutine.
For example, making a puzzle game, make the puzzle generator as a subroutine at 100, a win test as a subroutine at 200, and the main loop of asking for moves is lines 1-99.
You can put testing code somewhere high like 9000, then 1 GOTO 9000
to run
the test, 1 REM
to disable the tests.
You can get text and program listings out (if they're short) by using copy
(⌘C
or ^C
), but this only dumps into the Javascript console for now (JS
security is weird). I'm working on it.
TinyBasicWeb is deliberately a very small BASIC, and L1 is smaller than you expect. BUT! You can still do most things from large BASIC, with just a few extra steps.
SCR
: Very old BASICs used this instead of NEW
.
Multiple statements: Split these at :
into several lines, usually incremented by 1.
LET
.
10 A=B+C^3-99
(or sometimes **
instead of ^
)10 LET a=(b+(c^3)-99)
20 A=-B
20 LET a=(-1*b)
1 IF I>=0 AND I<=N OR A=5 THEN PRINT "FIVE"
1 IF ((i>=0)*(i<=n)+(a=5)) THEN ?"FIVE"
large: 10 FOR I=1 TO 100:PRINT I:NEXT I
tiny:
10 LET i=1
11 ?i
18 LET i=(i+1)
19 IF (i<=100) THEN GOTO 11
large: 10 ?"x,y";:INPUT x,y
tiny:
10 INPUT "x: ",x
11 INPUT "y: ",y
10 A=INT(RND(0)*100)+1
10 LET a=(RND*100%100+1)
: RND returns 0.0-0.9999 every time it is called. *100
makes it 0.0 to 99.99. %100
makes it integer 0-99. +1
makes it 1 to 100!large:
10 READ R:?R
20 READ R:?R
99 END
1000 DATA 100,200,0
tiny: See testdata.bas
. In TBW L2, this is replaced by reading files.
10 GOSUB 1000
11 ?dr
20 GOSUB 1000
21 ?dr
99 END
999 'Simulate DATA statements, dd is index, dr is result
1000 LET dd=(dd+1)
1001 LET dr=0
1010 IF (dd=1) THEN LET dr=100
1011 IF (dd=2) THEN LET dr=200
1099 RETURN
Arrays, Functions: No L1 replacement, there will be arrays and functions in L2.