PDA

View Full Version : UE1 - UT Testing optional parameters in functions


Zur
29th Dec 2008, 08:54 PM
In the following code :

function( optional int1, int int2 )
{
// doblah;
}

If I call the function without a first integer is it possible to test it hasn't been sent ? For example, can I do if( int1 > 0 ) ? Or will ucc fail to compile the code ? Or would this cause an error during execution ?

If the code is valid, is a default value given to int1 when I call the function without the first parameter ?

P.S: I purposefully placed an optional parameter first just in case it's a bad practise.

Wormbo
30th Dec 2008, 05:07 AM
Optional parameters must not be followed by non-optional parameters. You'll find that out when you try to compile the code.

As for detecting whether an optional parameter was specified or not: Omitted parameter values will end up being the null value of the corresponding type. Only in Unreal engine 3 you can specify a default value for parameters, UE1/2 always use 0, "", None, False, etc.

Zur
30th Dec 2008, 10:28 AM
As for detecting whether an optional parameter was specified or not: Omitted parameter values will end up being the null value of the corresponding type. Only in Unreal engine 3 you can specify a default value for parameters, UE1/2 always use 0, "", None, False, etc.

Ok, so there are dos and don't when using optionals. Thanks for explaining this.

So, about testing these optionals, let's say int2 is optional instead. if I do a if( int2 > 0), this should work ? I'm asking because the compiler usually complains if you test something that isn't a local variable. In this case (I haven't got round to testing it yet), the test will do fine then I assume ?