Can't "include" subroutines?

Blitz3D Forums/Blitz3D Programming/Can't "include" subroutines?

SuperRoboFan(Posted 2011) [#1]
I'm trying to make some reusable code I can use by means of the "Include" command. But if the code I am "Including" has any subroutines in it, like the following:

.Whatever

(some code here)

Return

the program simply ends. Does anyone have any idea what's going on here? The information on the "Include" command specifically states that you can "Include" subroutines, so I'm confused.


Yasha(Posted 2011) [#2]
There are a couple of things that this could be...

Firstly, are you aware that files can only be Included once in any given project? So the command doesn't work quite like, say, #include in C (which is a "pure" copy/paste): if you're trying to fill two subroutines from the same file, whichever one the compiler reaches second will end up empty. This could obviously have any kind of weird effects.

The other possibility is that the code is running ahead of the desired time. Since subroutines aren't encapsulated in any way, if you define one "above" the main part of your program, it will run first (i.e. if program flow reaches a .label, it won't skip past it to the Return, it will ignore the label and enter the body of the subroutine). Again, this could cause any number of weird errors, but the one that's probably affecting you is that Return is the same as End if there's nothing to Return to (as it presumably returns from the program's implicit "main" function to the calling process in the OS).

Both of these problems are best solved by simply never, ever using subroutines, as they contribute precisely nothing compared to functions, and just make your code more difficult to maintain and reason about. (Include files are only processed once so that function libraries can appear as dependencies to other libraries more than once without causing a multiple-definition error; and of course functions don't run without being called as they aren't actually part of the main program's control flow.)

Last edited 2011