Multiple Return Values in UnrealScript

UnrealScript doesn’t have built-in support for multiple return values like some modern languages. However, we can simulate this behavior using output parameters or by returning a custom struct. Here’s an example using output parameters:

class MultipleReturnValues extends Object;

// This function uses output parameters to return multiple values
function Vals(out int OutA, out int OutB)
{
    OutA = 3;
    OutB = 7;
}

// The main function in UnrealScript is often called DefaultProperties
function DefaultProperties()
{
    local int A, B, C;

    // Here we use the output parameters to get multiple values
    Vals(A, B);
    `log("A:" @ A);
    `log("B:" @ B);

    // If you only want a subset of the returned values,
    // you can ignore one of the output parameters
    Vals(, C);
    `log("C:" @ C);
}

In this UnrealScript version:

  1. We define a Vals function that uses output parameters OutA and OutB to return multiple values.

  2. In the DefaultProperties function (which is similar to main in other languages), we call Vals and capture the output in local variables A and B.

  3. We use the `log function to print the values, as UnrealScript doesn’t have a direct equivalent to fmt.Println.

  4. To demonstrate ignoring one of the values, we call Vals again but only capture the second output in C.

To run this code in Unreal Engine:

  1. Create a new UnrealScript file named MultipleReturnValues.uc in your project’s Scripts folder.
  2. Paste the above code into the file.
  3. Compile the script in the Unreal Editor.
  4. The output will be visible in the Unreal Console or log files.

Note that UnrealScript doesn’t have a direct equivalent to Go’s blank identifier (_), so we simply omit the first parameter when we want to ignore it.

This example demonstrates how to work with multiple return values in UnrealScript, even though the language doesn’t natively support this feature in the same way as some modern languages.