Hello,
Is it possible to define a function with variable number of arguments? I want to do:
RandomSpeak(string Speech1, string Speech2, ...)
{
int ran = Random(NumberOfArguments)
//etc... display a random message from the list.
}
Thanks!
Edit: [ANSWERED] in the subject
It's probably easiest if you define a global array that stores the arguments. That's not quite the same but it'd work.
Yeah, variable-argument lists are not supported in custom function definitions. Using some sort of global array (or the GlobalStrings) as Radiant suggests is probably the best solution, albeit messy.
Thanks for your answer. I think what I'll do is define a few functions like:
RandomSpeak2(sp1, sp2);
RandomSpeak3(sp1, sp2, sp3);
..
RandomSpeak6(sp1, sp2, sp3, etc.);
So that way I won't have to setup an array each time. Odds are I won't need more than a few (< 10) options anyway.
Maybe adding default values for function parameters would be a solution.
(like when you declare a function, int My_func (int x, int y = 20); )
Then again that may be annoying to code and I doubt it'd be used all that often.
I don't think the script engine supports optional arguments either, which would be needed in order for that to work.
Well it's just user-custom functions can't use optional argument lists.
Built-in functions like Display() can accept various amount of arguments.
Janik -> it doesn't, I was suggesting that to CJ actually. But it's not something most people would use, I think.