A string variable in procedure call?-Gosub,Other?

Blitz3D Forums/Blitz3D Beginners Area/A string variable in procedure call?-Gosub,Other?

Galdy(Posted 2011) [#1]
Is there away to make a procedure call to a label, but with a string variable that has the name in it? I tried Gosub "labelname$"
That gave me anexpecting end of file error. So i assume that isn't possible with the Gosub command. Is there another way?

Galdy,


Yasha(Posted 2011) [#2]
I assume you want to do this so you can change the procedure being called in a given expression at runtime?

Unfortunately, for this to work, you need a language that has either function pointers or first-class functions. Blitz3D doesn't support either of those things natively.

You can get really indirect support for function pointers using FastPointer, but be warned that that's really not aimed at beginners.

The best way to do what you want in B3D is to restructure your logic so that all procedures are called statically - that probably means putting an If or Select structure driven by a "function ID" tag around your call site.

EDIT: Also, unless there's a very specific reason, general advice is to avoid Gosub entirely, as it serves pretty much no useful purpose and encourages poor style.

Last edited 2011


Galdy(Posted 2011) [#3]
No, actualy I was hoping to shorten the routine that makes the calls. It's a For-Next loop that needs to call a different procedure label each time through. This means i'll have to put about 22 'If- then-gosub' statements insie the loop to go to each subroutine. It will work. I just was hoping to do it more efficiently.


GfK(Posted 2011) [#4]
Try using Select/Case.