function with multiple inputs...
BlitzPlus Forums/BlitzPlus Programming/function with multiple inputs...
| ||
Is there any way is Bitz to have a function that can have a variable number of input variables? |
| ||
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. ? |
| ||
can you explain your question better i dont really get what your saying |
| ||
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? =) |
| ||
where did "bye" come from soja ;) |
| ||
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. |
| ||
Papa: Indeed =) Strange things my brain does. aab: I think you're right |
| ||
Pass in a type. |
| ||
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) |
| ||
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" |
| ||
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? |
| ||
I'm pretty sure passing a bank handle would do the trick. |
| ||
Why not just pass an array? |