How do I detect if a function param was passed or not?

Get help using Construct 2

Post » Sun May 24, 2015 4:33 am

Hi, I have a function that I would like to use some sensible defaults if nothing is overridden, but allow for passing in of values. So in the function I look at the values held by Function.Param(0..n) and see if they seem reasonable. If not, I use a default value, otherwise I assign the value passed in by the function to a local variable and use it.

The problem is Function.Param() returns 0 if the script didn't pass any value, but 0 is a valid argument to pass in some cases. Is there any way to know whether the 0 returned by Function.Param() is something that was passed in or just the default 0? If the default of Function.Param() was null or NaN I could test for that and know that nothing was passed in.

Another way to put the question is, "Is there a better way to define default Function parameters?"

Thanks!
B
42
S
14
G
2
Posts: 50
Reputation: 4,342

Post » Sun May 24, 2015 5:04 am

Function.ParamCount tells you how many parameters were passed.
ImageImageImage
B
71
S
22
G
249
Posts: 3,764
Reputation: 138,579

Post » Wed May 27, 2015 8:50 pm

Thank you, blackhornet! That should do it.
B
42
S
14
G
2
Posts: 50
Reputation: 4,342


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 14 guests