Click or drag to resize

SpectatorToPlayerRequest Class

Turns the current user from spectator to player in a Game Room.
Inheritance Hierarchy
SystemObject
  BaseRequest
    Sfs2X.RequestsSpectatorToPlayerRequest

Namespace:  Sfs2X.Requests
Assembly:  SmartFox2X (in SmartFox2X.dll) Version: 1.8.0.0 (1.8.0)
Syntax
C#
public class SpectatorToPlayerRequest : BaseRequest
Constructors
  NameDescription
Public methodSpectatorToPlayerRequest
See SpectatorToPlayerRequest(Room) constructor.
Public methodSpectatorToPlayerRequest(Room)
Creates a new SpectatorToPlayerRequest instance.
Top
Remarks
If the operation is successful, all the users in the target Room are notified with the SPECTATOR_TO_PLAYER event. The operation could fail if no player slots are available in the Game Room at the time of the request; in this case the SPECTATOR_TO_PLAYER_ERROR event is dispatched to the requester's client.
Examples
The following example turns the current user from spectator to player in the last joined Game Room:
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.SPECTATOR_TO_PLAYER, OnSpectatorToPlayerSwitch);
    sfs.AddEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, OnSpectatorToPlayerSwitchError);

    // Switch spectator to player
    sfs.Send( new PlayerToSpectatorRequest() );
}

void OnSpectatorToPlayerSwitch(BaseEvent evt) {
    User user = (User)evt.Params["user"];
    Console.WriteLine("Spectator " + user.Name + " is now a player");                           // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Spectator " + user.Name + " is now a player");          // UWP
}

void OnSpectatorToPlayerSwitchError(BaseEvent evt) {
    Console.WriteLine("Unable to become a player due to the following error: " + (string)evt.Params["errorMessage"]);                       // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Unable to become a player due to the following error: " + (string)evt.Params["errorMessage"]);      // UWP
}
See Also