1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. 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.

UE1 - UT Testing optional parameters in functions

Discussion in 'Programming' started by Zur, Dec 29, 2008.

  1. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    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.
     
  2. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,915
    Likes Received:
    36
    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.
     
  3. Zur

    Zur surrealistic mad cow

    Joined:
    Jul 8, 2002
    Messages:
    11,717
    Likes Received:
    4
    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: Dec 30, 2008

Share This Page