Limit to variables passed to a function

Blitz3D Forums/Blitz3D Beginners Area/Limit to variables passed to a function

Nicstt(Posted 2006) [#1]
Curious if anyone knows if there is a limit to the amount of variables passed when calling a function?

Example I have below:

Function AdviceWindowOption(number, gfxGeneric, custom_width, custom_hight, fntGeneric, message$, boolean)

thanks:)


(tu) sinu(Posted 2006) [#2]
I don't think their is a limit that you could really exceed, you wouldn't give a ton of parameters to a function anyway but i just tested 26 and it works.


jfk EO-11110(Posted 2006) [#3]
When there's a limit for the length of a line then this may be the limit. Other than that I am not aware of any limit, although it wouldn't be surprising if there's some kind of max, within the range of reason.

you may try this:

wr=writefile("test.bb")

l$="dummy=test("

ma=10000 ;test 10 thousand arguments...
for i=0 to ma
 l$=l$+rand(10)+","
next
l$=l$+rand(10)+")"

writeline wr,l$
writeline wr,"waitkey()"
writeline wr,"end"

l$=" function test("
for i=0 to ma
 l$=l$+"x"+i+","
next
l$=l$+"x"+(ma+1)+")"

writeline wr,l$
writeline wr,"End Function"

closefile wr



Sir Gak(Posted 2006) [#4]
As I understand things, the best way to use a function is to keep your function tight, as in, do only one or two things, but do them well. Passing a boatload of parameters to a function seems, oh, I dunno, defeating the whole point of the simplicity of a function. Technically, I guess, there is no reason you can't do 1000+ things in a function, but it seems to me that it is more efficient and effective to limit what a function does. If you need more functionality (pun intended), create more functions, one per job to be accomplished.


Nicstt(Posted 2006) [#5]
thanks for all the answers, appreciate it:)

@Sir Gak

Agree, although there are instances when more not less is more:)

The function I am writing will handle messages to use, and where needed take a reply from up to 3 buttons.

I also wanted the function to have the ability to create the windows and the buttons if needed all without using any global variables. Although global variables such as gfx and font can be passed if desired.

Looking good, going to be a fairly big function - and I dislike em big on general principle.


Sir Gak(Posted 2006) [#6]
Another reason to limit the number of things a given function does, is to make it easier to debug if things aren't working the way you intended.