Diarkis Inc.

Top > Blog > Moving From One Room to Another

Moving From One Room to Another

moving-from-one-room-to-another

When you need to move from one room to another, there is a convenient method that does exactly that helping you keep the application code base clean and simple.

You may either use the event listeners or a callback with this method.

With Event Listeners

room.OnLeave += HandleDiarkisRoomOnLeave;
room.OnJoin += HandleDiarkisRoomOnJoin;

// leaveMessage will be broadcasted when leaving the current room - If you pass an empty byte array, the message will not be sent
byte[] leaveMessage = Encoding.UTF8.GetBytes("Good bye");
// joinMessage will be broadcasted when joining a new room - If you pass an empty byte array, the message will not be sent
byte[] joinMessage = Encoding.UTF8.GetBytes("Hello world");
// roomID is the new room ID to join
room.Move(roomID, leaveMessage, joinMessage);

private void HandleDiarkisRoomOnLeave(bool success)
{
    if (!success)
    {
         // Failed to leave the current room
    }
}

private void HandleDiarkisRoomOnJoin(bool success, uint roomCreatedTimeInMilliseconds)
{
    if (!success)
    {
        // Failed to join the new room
    }
}

With The Callback

// leaveMessage will be broadcasted when leaving the current room - If you pass an empty byte array, the message will not be sent
byte[] leaveMessage = Encoding.UTF8.GetBytes("Good bye");
// joinMessage will be broadcasted when joining a new room - If you pass an empty byte array, the message will not be sent
byte[] joinMessage = Encoding.UTF8.GetBytes("Hello world");
// roomID is the new room ID to join
room.Move(roomID, leaveMessage, joinMessage, OnMoveCallback);

private void OnMoveCallback(bool success, uint roomCreatedTimeInMilliseconds)
{
    if (!success)
    {
        // Handle error here...
    }
    // Do something awesome here!
}

C# client v0.1.14 and above.

Diarkis enables massive multiplayer network communications.

Contact Us
このエントリーをはてなブックマークに追加

Recommendations

If you are interested in learning more about Diarkis, please contact us here.

Contact Us Request Documents
PAGE TOP