I can't believe you've been programming for five years and have never used return!
Half the point of functions are that they allow you to return a value...
Here is simple example of how to use return:
Function Add#(A#, B#)
Return A#+B#
End Function
X# = Add#(10, 2)
Here is another example. Note that you can use Return anywhere in the function and it will exit the function immeidatley and return that value. Specifying no return value with return will return false or 0. You can even use Return in functions that have no return type specified after the function name. Just don't put anything after the Return.
Function GreaterThan%(A%, B%)
If A > B Then Return True
If A < B Then Return ' This returns 0 or False, which is the default value returned by Return.
' All functions behave as if the last line is Return, so if we get here because A = B, the function will still return False.
End Function
Note that if a function returns a value, you can choose to use it like a function that does not return a value and simply not assign it to anything. Ie, you could put:
GreaterThan(10, 5)
In your code, and there would be no error, even though GreaterThan is returning a value, and you're not passing that on to anything.
A lot of times people make functions that do something like load a background image and instead of returning the image handle they might store that in some preprogrammed location and instead have the function return an error code... a boolean value... to tell them if the operation was successful. They might then choose to ignore that return value, or use it if failure is not an option. Ie:
Function LoadLevel%(LevelName$)
If the level loaded Then Return True
End Function
If Not LoadLevel("ep1lv1.wad")
RuntimeError("Level failed to load!")
End
EndIf
Hefully that makes it all clear. I'm still in shock over the return thing. I thought you coded a game or two. You did that without returning any values from functions?
How long have you been coding? :-)
I didn't use function returns in my first five years of coding either, but that's because I started coding in the 1980's and I don't think they even had C back then, or if they did it was only available on mainframes not home PC's. Basic back then had a line number on every line and gosub and goto statements instead of functions so if you wanted to return a value from anything you had to use a global variable... which was the only kind of variable back then. :-) Hey, I bet that's what you've been doing... Using globals to return the results of functions? I still do that sometimes because unless you return arrays you can only return one variable when you return something from a function with return.