UE1 - UT Testing optional parameters in functions

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
In the following code :

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

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
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

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
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 ?
 
Last edited: