Channel Directions in UnrealScript
When using function parameters in UnrealScript, you can specify if a parameter is meant to only send or receive values. This specificity increases the type-safety of the program.
In UnrealScript, we don’t have built-in channels like in some other languages. Instead, we use function parameters with the out
keyword to simulate sending values, and regular parameters for receiving values.
The Ping
function takes an out
parameter, which means it’s used for sending a value out of the function. It would be a compile-time error to try to read from this parameter inside the function.
The Pong
function takes two parameters: one for receiving a value (InMessage
) and one for sending a value out (OutMessage
with the out
keyword).
In the Execute
function (which serves as our main function), we demonstrate how to use these functions:
- We declare two local string variables to hold our messages.
- We call
Ping
, passingPingMessage
as an out parameter. - We then call
Pong
, passingPingMessage
as the input andPongMessage
as the output. - Finally, we log the result using UnrealScript’s logging function.
To run this code, you would typically include it in an UnrealScript class and either call the Execute
function from elsewhere in your game code, or set up the class to be automatically instantiated and executed by the Unreal Engine.
Note that UnrealScript doesn’t have a direct equivalent to Go’s channels, so this example demonstrates the closest approximation using UnrealScript’s parameter passing mechanisms.