I long wanted to code on a mobile device, or at least fiddle with code, which is more plausible. Most apps made for that are huge and involved, but there are exceptions.
Enter X11-Basic. It's a 4.6MB app available in F-Droid, runs on very old Android devices, and comes with a ton of examples. Also a 700-page reference manual, which is daunting at first sight. I tried and failed twice to learn the dialect. But third time was the charm; see below for a survival guide. It applies to version 1.27, latest as of mid-April 2022.
For development I installed the Linux version from source, which is quick but tricky. Tip: use make static
as explained in the documentation, and manually copy the resulting executables to /usr/local/bin
or so.
Only three because I took a long break for most of 2022 and early 2023:
Remember that a big part of the fun with Basic games is tweaking them. For example I changed Land/Lord on the tablet to say "disaster!" out loud when the plague strikes, while on the phone I trimmed down the text to fit a very small screen. Figure out your own variations!
Don't panic! While the reference manual is over 700 pages long, most of that is a list of all statements and functions. You only need to read — or at least skim — the first few chapters. Mainly, an X11-Basic program looks like this:
' main program first
@hello
quit
procedure hello()
print @hello$()
return
function hello$()
return "Hello, world!"
endfunc
You can expand @ to gosub
for procedures, but not functions. Other notes:
color()
modifier is explained on page 492 of the manual, under print
.
div
and mod
operators have low precedence; use them with parentheses.
dim
a scalar variable, so just initialize it.
then
keyword isn't supported; there's no single-line if
.
for
loop variable in next
is mandatory.
continue
only works in select
; use goto
in loops.
input
prompt makes it crash.
Speaking of which, there are nice touches like array literals (only for numeric arrays):
chances() = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Also the exit if
statement can make for nice compact code in some cases. On the minus side, the parser is kind of fragile. Error messages can be confusing, or worse, absent. To wit:
> print "Hello, ": print "world!"
Hello, ": PRINT "world!
Or for an even more baffling example:
> let a = 1: let b = 2
> print a
0
> print b
0
Not to mention (a real error I made a few times):
> dim a(10)
> let a[0] = 1
> print a(0)
0
> print a[0]
1
But keep it simple and things should work. Well enough. Usually.