[26 Feb 2011] dont understand args

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
asymetrix
Posts: 6
Joined: Tue Feb 22, 2011 8:14 pm

[26 Feb 2011] dont understand args

Post 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.
User avatar
Allanon
Posts: 742
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

[27 Feb 2011] Re: dont understand args

Post 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
----------------------------
[Allanon] Fabio Falcucci | GitHub (leaving) | Gitea (my new house) | My Patreon page | All my links
asymetrix
Posts: 6
Joined: Tue Feb 22, 2011 8:14 pm

[27 Feb 2011] Re: dont understand args

Post 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 !
Locked