Page 1 of 1

[26 Feb 2011] dont understand args

Posted: Sat Jun 13, 2020 5:32 pm
by asymetrix
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sat, 26 Feb 2011 21:37:52 -0000

can anyone tell me why this code shows number of parameters passed to function as 0 ?

why is Hollywood so annoying ? and not just return 2 ?

Code: Select all

Function p_test(param1,param2,...)
Print("param1=",param1, "param2=",param2,"number of parameters to function=", arg.n)
EndFunction
p_test(1,2)
WaitLeftMouse
what i am trying to get done is create a function that can use variable number of inputs and do different things.

eg

if function use 2 params do this code []

if function use 3 params do this code instead []

any help appreciated.

[27 Feb 2011] Re: dont understand args

Posted: Sat Jun 13, 2020 5:32 pm
by Allanon
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 27 Feb 2011 00:09:56 -0000

Hello, In your code you have defined the first two arguments as fixed, after them there are a variable number of arguments that are 0 if you call p_test(1, 2)!

Try defining your function with:

Code: Select all

Function p_test(...)
Print("param1=",param1, "param2=",param2,"number of parameters to function=", arg.n)
EndFunction
you will see that executing: p_test(1, 2)

arg.n will be 2

Hollywood it's not annoying, trust me! ;)

Allanon

[27 Feb 2011] Re: dont understand args

Posted: Sat Jun 13, 2020 5:32 pm
by asymetrix
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 27 Feb 2011 22:45:39 -0000

Hi

thanks for the info. I tried the example and it works as shown.

just adding (...) makes life much better.

thanks, I was so annoyed yesterday..

cheers !