ON GOTO

Anything QL Software or Programming Related.
Post Reply
User avatar
dden
ROM Dongle
Posts: 43
Joined: Thu Jan 19, 2017 8:56 am

ON GOTO

Post by dden »

I'm converting a program written in a Microsoft Basic. It includes a lot of ON x GOTO statements, with a wide range of number values for 'x' (an adventure game, where the ON statements are used to jump to verb/noun/place codes).

Does anyone know if there is a limit on the number of line number parameters I should adhere to, before I should split it into multiple statements?

e.g.

x=RND(1 to 36)
ON x GOTO <list of 36 line numbers>

seems to work, on Qpc2 at least, but I don't know if there is a limit in SuperBasic.


David
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: ON GOTO

Post by dilwyn »

Just for the sheer hell of it, I wrote a short basic program which generated another basic program with up to 20,000 values of x. It works on a JS ROM with surprisingly high values.

Obviously, totally unwieldy and way beyond practical usage, but weirdly it seems to work until the ON x GOTO line_numbers range makes the line of BASIC too big for SuperBASIC, at which it simply freezes or just plain refuses to load that long line. By that point it's getting pretty pointless.

The Jan Jones bible says that the 'x' reference boils down to an integer value, but the limiting factors seem to be more (a) line length of the ON x GOTO... (b) practicality of juggling that many GOTO references (c) you run out of line numbers in the program (no more than 32k lines of SuperBASIC while some basics will allow up to 65,536 lines).

So, it would comfortably handle the 36 numbers as you mentioned, but by then a list of 36 line numbers would be very clumsy to handle anyway. Maybe better to chop it up into 3 or 4 separate ON x GOTO list of line numbers just to make it easier to handle.

One small thing to watch out for - if you do something like:
x=12
ON x GOTO list of 10 line numbers

you'll get an error in QL basic (not enough line numbers), but some versions of BASIC will just skip the line if there is no matching line number. Which makes it hard to debug and you need to cater for this when converting to QL BASIC, something like:

x=12
IF x < 11 then
ON x GOTO list of 10 line numbers
END IF
which would make it work like those versions of basic.


Post Reply