Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Is it possible to branch to a label that is stored as a string variable?

Years of Service
User Offline
Joined: 6th Dec 2012
Location: UK
Posted: 19th Sep 2016 14:16
This is probably a result of my head being stuck in some really old dialects of BASIC (i.e. BBC BASIC) but I can't see any way in Dark Basic Pro to replicate the method that I used back then to do this quick and easy thing...

What I'm trying to do is branch to one of many labels based on a variable.

An example to illustrate what I mean:

Say I had a game in which the data for the various "rooms" was held in DATA statements that followed labels.
In old versions of BASIC that I'm used to, I would simply store the data like this:

Data ... (room data)
Data ... (room data)

And then, if the variable "room" held the player's current room-number, I would construct a string
and then simply

That would set the data-pointer to the appropriate block of data, and I'd simply read the room data.

There doesn't seem to be any way in Dark Basic Pro to branch (e.g. RESTORE, GOSUB, etc) to a label that is held as a variable.
It seems labels must be specified absolutely, e.g. RESTORE ROOM01
Am I missing something? (I won't even go there with "ON x GOTO 100,200,300"!)

I can see that I would be able to do this if the data was stored in external data-files (i.e. you can use a string to construct a path and/or filename and load the data from outside of your program) but I really want to be able to work with (and see, and edit) the data directly within my main code.

I could, of course, simply store all of the DATA statement as one vast sequence, and read through it, ignoring the data until I reach the required "block", but it seems really inefficient to do it that way when (ideally) I should be able to leap directly to the required label.

Hope I've described the problem clearly (?) and any tips would be much appreciated!
Years of Service
User Offline
Joined: 4th Nov 2013
Posted: 19th Sep 2016 21:13
DarkBasic does not allow calling a label using a variable. You will need Select/Case for this. Select/Case can also be used as an equivalent to On Goto.

Login to post a reply

Server time is: 2023-05-29 00:16:59
Your offset time is: 2023-05-29 00:16:59