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:
In this UnrealScript version:
We define a
Vals
function that uses output parametersOutA
andOutB
to return multiple values.In the
DefaultProperties
function (which is similar tomain
in other languages), we callVals
and capture the output in local variablesA
andB
.We use the
`log
function to print the values, as UnrealScript doesn’t have a direct equivalent tofmt.Println
.To demonstrate ignoring one of the values, we call
Vals
again but only capture the second output inC
.
To run this code in Unreal Engine:
- Create a new UnrealScript file named
MultipleReturnValues.uc
in your project’s Scripts folder. - Paste the above code into the file.
- Compile the script in the Unreal Editor.
- 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.