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.

2D All the way! / Gosub string?

Author
Message
Levanthus
21
Years of Service
User Offline
Joined: 17th Apr 2003
Location: Cumbria, UK
Posted: 8th Sep 2003 21:02
Is there anyway to make a gosub depending on a value? for example instead of having to make a million statements like:
If a=1 then gosub situation1
if a=2 then gosub situation2
is there anyway to make it like
gosub situation+a
or something like that? or am i just hoping against all hope that it could be THAT easy?

Are you a tool? can I step through to find another plane or just the shadow of a man?
Angeleyes
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location:
Posted: 8th Sep 2003 21:37 Edited at: 8th Sep 2003 21:38
Yes....this is one of those BASIC things that was sadly left out of DB.

If I remember correctly the syntax was:

On LTM Gosub 1000,1050,4000,5000,7600

This was a very easy way to get a program to branch off to different routines based on the value stored in a variable.

Shame the DB Team did not get their act together and add this to DB....Ah well!

Ta ta for now
Mary
David T
Retired Moderator
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 8th Sep 2003 22:49
It also seems this is in the wroing forum

I'd be really useful to haev something like that, though because dbp is compiled to asm I think it might not be that easy.

Theres no place like 127.0.0.1
There are 10 people in this world, those who understand binary and those who don't
Bus station = where bus stops. Train station = where train stops. Workstation = ?
Mentor
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 13th Sep 2003 00:11
on the Spectrum it was indeed

Gosub value

where value was the line number and could be calculated if you wanted

Gosub 1000+var

which was most useful, the nearest in db would be to use the case statement, but that is cumbersome and no better compiled code wise than repeated..

if
then
else if
then
else if
etc

in compiled code this would be difficult to impliment and risky, since a program mistake could send the whole code out of control and crash the machine, you could have the code use the IDE line numbers as reference and jump to those as in the compiler could remember where the line number was in relation to the compiled code and then use those adresses and a lookup table to allow jumps, but this would bulk up the code massivley if you need a table for the addresse of every 5th byte or so in the code, most ungood (you would need that since the jump by variable could go to any point in the code and the compiler would have no way of knowing what locations would be used and what wouldnt).

Mentor.
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 13th Sep 2003 21:42 Edited at: 13th Sep 2003 21:43
and in Play Basic it's..

On Variable Gosub/Goto Label1,label2,label3 etc. For safety you can only gosub/goto a label however. This protects the user from jumping to an illegal opcode/address.. Much faster than If/then, select cases though

Kevin Picone
Play Basic - Visible Worlds - Kyruss II
[url]www.underwaredesign.com[/url]

Login to post a reply

Server time is: 2024-05-05 20:01:00
Your offset time is: 2024-05-05 20:01:00