Variable number of parameters for a function?

Blitz3D Forums/Blitz3D Beginners Area/Variable number of parameters for a function?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Kind of.

Basically, in your function definition, you can give some variable default parameters, like this:
Function PrintLines(Message$, howmany% = 1)
...

Notice the " = 1" assignment in the function definition. This means that if you call the function without specifying a second parameter, it will use the value 1 as the second parameter. If you do specify it, it will be whatever you sent. Here's a working code example:
PrintLines("Hello")
PrintLines("Echo", 5)

Function PrintLines(Message$, howmany% = 1)
	For i% = 1 To Abs(howmany)
		Print Message
	Next
End Function


So, as you can see, it's kind of a "variable" number of parameters, though it's not truly, since all parameters are specified one way or another, just not necessarily by you.

Note that if you have a function with default parameters, every parameter after the first default parameter must also have a default parameter. That is to say, this will not work:
Function PrintLines(Message$="", howmany%) ; <--- WON'T WORK
...


Dig it?