Channel Directions in UnrealScript

class ChannelDirections extends Object;

// This `Ping` function only accepts a parameter for sending
// values. It would be a compile-time error to try to
// receive on this parameter.
function Ping(out string Message)
{
    Message = "passed message";
}

// The `Pong` function accepts one parameter for receives
// (`InMessage`) and a second for sends (`OutMessage`).
function Pong(string InMessage, out string OutMessage)
{
    OutMessage = InMessage;
}

// Main function to demonstrate the usage
function Execute()
{
    local string PingMessage, PongMessage;

    Ping(PingMessage);
    Pong(PingMessage, PongMessage);
    `log(PongMessage);
}

defaultproperties
{
}

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:

  1. We declare two local string variables to hold our messages.
  2. We call Ping, passing PingMessage as an out parameter.
  3. We then call Pong, passing PingMessage as the input and PongMessage as the output.
  4. 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.