function with multiple inputs...

BlitzPlus Forums/BlitzPlus Programming/function with multiple inputs...

aab(Posted 2004) [#1]
Is there any way is Bitz to have a function that can have
a variable number of input variables?


CS_TBL(Posted 2004) [#2]
uh.. o_O

like:

Function (a)
Function (a,b)
Function (a,b,c)
Function (a,b,c,d)
Function (a,b,c,d,e)

etc. ?


Regular K(Posted 2004) [#3]
can you explain your question better

i dont really get what your saying


soja(Posted 2004) [#4]
Yes, you just have to make some of your parameters have default values.
Function something(s$="hello", b=1)

This allows you to call...
    something() ; s$ is "hello" and b is 1
    something("goodbye") ; s$ is "goodbye" and bye is 1
    something("goodbye", 5) ; s$ is "goodbye" and bye is 5

The only trick is that all the parameters with default values have to come after ones without.

This all sounds familiar. Didn't I answer something like this very recently? =)


REDi(Posted 2004) [#5]
where did "bye" come from soja ;)


aab(Posted 2004) [#6]
No, thats not what I'm asking. I'm asking for a function command where the user can put in any number of variables eg: a hundred if (s)he wishes. I dont think there is a way in Blitz.


soja(Posted 2004) [#7]
Papa:
Indeed =) Strange things my brain does.

aab:
I think you're right


Rob Farley(Posted 2004) [#8]
Pass in a type.


MSW(Posted 2004) [#9]

I dont think there is a way in Blitz.



no implicably built in way...but Blitz has enough capability that you can easily do this manualy if need be

for example: store the variables in a bank and pass the bank handle to the function...

another way is to use a type, as Rob said...

Actually you really DON'T want to directly pass hundreds of variables...you start getting into stack overflows and such...pass by refrence instead (pass handles, pointers, memory addresses...instead of large chunks of data)


aab(Posted 2004) [#10]
Thanks.
The bank wouldnt help because its the fact that i wouldnt know how many vars were going in thats the problem.
But the type could be used in that way..

"Cheers, Rob"


AndyBoy_UK(Posted 2004) [#11]
You could send in a memory address and a number of vars that are contained in the bank

Function dostuff(numberOfElements%, memoryAddress)

... would that work?


Phil Newton(Posted 2004) [#12]
I'm pretty sure passing a bank handle would do the trick.


DrMartin(Posted 2004) [#13]
Why not just pass an array?