Skip to main content

Create Standard Room

Create a Standard Room to start a multiplayer session with a fixed number of players. This method is ideal for creating public rooms with auto-matching or private rooms for invited players.

Method Signature

MoitribeSDK(gameId, 'createstandardroom', params, callback)

Parameters

ParameterTypeRequiredDescription
variantnumberNoGame mode variant (0-255)
min_automatch_playersnumberNoMinimum players for auto-matching
max_automatch_playersnumberNoMaximum players for auto-matching
invitedPlayerIDsstring[]NoArray of player IDs to invite
exclusive_bitmaskstringNo8-bit mask for player roles
onRoomCreatedfunctionYesCallback when room is created
onMessageReceivedfunctionYesCallback for incoming messages
onPeerJoinedfunctionYesCallback when players join
onPeerLeftfunctionYesCallback when players leave
onLeftRoomfunctionYesCallback when you leave room

Examples

Public Auto-Match Room

Create a public room that automatically matches 2-4 players:

MoitribeSDK('my-game-id', 'createstandardroom', {
variant: 1,
min_automatch_players: 2,
max_automatch_players: 4,
onRoomCreated: (status, room) => {
if (status) {
console.log('Room created:', room.roomID);
console.log('Waiting for players...');
} else {
console.error('Failed to create room');
}
},
onMessageReceived: (messageData, senderID, isReliable) => {
console.log('Message from', senderID);
// Handle incoming game data
},
onPeerJoined: (room, participantList) => {
console.log('Player joined. Total:', participantList.length);
},
onPeerLeft: (room, participantList) => {
console.log('Player left. Total:', participantList.length);
},
onLeftRoom: (status, roomID) => {
console.log('Left room:', roomID);
}
}, (result) => {
console.log('Create room request sent:', result);
});

Private Invitation Room

Create a private room and invite specific players:

MoitribeSDK('my-game-id', 'createstandardroom', {
variant: 0,
invitedPlayerIDs: ['player123', 'player456', 'player789'],
exclusive_bitmask: '00000001',
onRoomCreated: (status, room) => {
if (status) {
console.log('Private room created:', room.roomID);
console.log('Share this invitation code with friends');
}
},
onMessageReceived: (messageData, senderID, isReliable) => {
// Handle game messages
},
onPeerJoined: (room, participantList) => {
console.log('Invited player joined the room');
},
onPeerLeft: (room, participantList) => {
console.log('Player left the room');
},
onLeftRoom: (status, roomID) => {
console.log('You left the private room');
}
}, (result) => {
console.log('Private room creation result:', result);
});

Response Format

The callback receives a response object:

{
success: boolean;
room?: Room; // Room object if successful
error?: string; // Error message if failed
}

Room Object

When a room is successfully created, you'll receive a Room object containing:

{
roomID: string; // Unique room identifier
creatorID: string; // Your player ID
status: RoomStatus; // Current room status
variant: number; // Game mode variant
autoMatchWaitSeconds: number; // Auto-match wait time
participants: Participant[]; // Array of players
isAutoMatch: boolean; // True for public rooms
// ... other room properties
}

Auto-Matching Behavior

When using auto-matching:

  • The room waits for min_automatch_players to start
  • Maximum of max_automatch_players can join
  • Players are matched based on skill and availability
  • Room status changes from AUTO_MATCHING to CONNECTING to ACTIVE

Error Handling

Common errors and their meanings:

  • Invalid Parameters: Required parameters are missing
  • Player Not Authenticated: User needs to authenticate first
  • Room Creation Failed: Server-side error during creation
  • Invalid Variant: Variant number is out of range (0-255)
warning

Always implement the onRoomCreated callback to handle both success and failure cases. The room creation is asynchronous, so you'll need to wait for the callback before proceeding with game logic.

Best Practices

  • Set reasonable auto-match ranges (e.g., 2-4 players for most games)
  • Use variants to distinguish different game modes
  • Implement proper error handling for all callbacks
  • Show loading states while waiting for auto-matching
  • Handle room lifecycle events gracefully

Next Steps