Sign In

GOSUB within functions?

#1✎ 65Gaelstrom_ValenceDrawingI like to draw!HobbiesIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthFirst MonthJoined in the very first month of SmileBASIC SourceWebsiteThe manual says it can't be used, but it seems to work fine for me? Is it referring to something else, or is the wording there a bit messed up?
Posted 4 months ago
Edited 4 months ago
by Gaelstrom_Valence

#2✎ 169012Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfIt originally wasn't possible but they fixed it in version 3.5.2 or something.
Posted 4 months ago

#3✎ 102seggiepantsEven if it works now, your really shouldn't be mixing GOSUB and functions, just use functions.
Posted 4 months ago

#4✎ 65Gaelstrom_ValenceDrawingI like to draw!HobbiesIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthFirst MonthJoined in the very first month of SmileBASIC SourceWebsite

Even if it works now, your really shouldn't be mixing GOSUB and functions, just use functions.

This came up because I wanted to see if I could use ON within functions. I ended up going with GOTO anyways, but in either case... Well, I'm not sure if my speed test thing is accurate... but as far as I know, both GOSUB and GOTO with the ON instruction are faster than:
DEF THING CTRL
IF CTRL==0 THEN FUNC1
IF CTRL==1 THEN FUNC2
IF CTRL==2 THEN FUNC3
IF CTRL==3 THEN FUNC4
Posted 3 months ago
Edited 3 months ago
by Gaelstrom_Valence

#5✎ 169012Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfYou could use ELSEIF for that
But ON/GOTO/GOSUB is slightly faster
Even without GOSUB, you can use another GOTO instead of RETURN:
DEF THING CTRL
VAR X
ON CTRL GOTO @0,@1,@2,@3
@RET
PRINT X
RETURN
@0
X=0
GOTO @RET
@1
...
END
But you should only do this in extreme circumstances when you need a tiny bit more speed (the speed difference between this and ON GOSUB is very small)
Posted 3 months ago