gameinstancemanager - TogetherGames/Public-Corona-Lua GitHub Wiki

GameInstanceManager

together.GameInstanceManager

Overview

The GameInstanceManager is used for fetching and finding matches that exist for the current game.


Members

table GameInstances

Stores all the GameInstances contained in the Manager.


Methods


Add()

Adds a GameInstance to the manager internally without persistence.

Note
This method is deprecated

Returns void
Syntax
GameInstanceManager:Add( gameInstance )
Parameters

TogetherGameInstance gameInstance

Instance of a GameInstance to add internally

--------------------------------------------------------------------------------

FindByGameInstanceID()

Finds the GameInstance with the specified GameInstanceID if it exists, otherwise returns nil.

Syntax
GameInstanceManager:FindByGameInstanceID( gameInstanceID )
Parameters

number gameInstanceID

The ID of the GameInstance to find

--------------------------------------------------------------------------------

GetCount()

Gets the number of GameInstances currently managed internally.

Returns number
Syntax
GameInstanceManager:GetCount(  )

Get()

Gets the GameInstance at the specified index if it exists, otherwise return nil.

Syntax
GameInstanceManager:Get( index )
Parameters

number index

The index of the GameInstance to find

--------------------------------------------------------------------------------

IndexOf()

Returns the index of the specified GameInstance if it exists, otherwise returns nil.

Returns number
Syntax
GameInstanceManager:IndexOf( gameInstance )
Parameters

TogetherGameInstance gameInstance

Instance of the GameInstance to find the index of

--------------------------------------------------------------------------------

IndexOfByGameInstanceID()

Returns the index of the GameInstance with the specified GameInstanceID if it exists, otherwise returns -1.

Returns number
Syntax
GameInstanceManager:IndexOfByGameInstanceID( gameInstanceID )
Parameters

number gameInstanceID

The ID of the GameInstance to find the index of

--------------------------------------------------------------------------------

Remove()

Removes a GameInstance from the internally managed list. This does not delete the GameInstance from the Game persistently.

Note
This method is deprecated

Returns void
Syntax
GameInstanceManager:Remove( index )
Parameters

number index

The index of the GameInstance to be removed internally

--------------------------------------------------------------------------------

Create()

Creates a new GameInstance. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:Create( gameInstanceType, gameInstanceSubType, roomID, maxUsers, passTurn, gameInstanceProperties, gameInstanceUserProperties, callbackFunc )
Parameters

string gameInstanceType

The type of GameInstance to create. Potentially, a Game could have several types of GameInstance types within it. Type is limited to 16 characters.

[string](#) gameInstanceSubType

The subtype of the GameInstance that will be created. Potentially, a Game could have several sub types within it. SubType is limited to 16 characters.

[number](#) roomID

The ID of the room the rematch GameInstance is created in. Pass 0 to bypass room creation.

[number](#) maxUsers

The max number of users the GameInstance supports. Pass in 2 for a two player game.

[boolean](#) passTurn

A boolean indicating whether the turn should be passed immediately onto the next User. When true, the TurnUserID will actually be set to nil. When the next User joins the GameInstance, the TurnUserID will be set to them.

[PropertyCollection](./propertycollection) gameInstanceProperties

The properties to assign to the GameInstance. Pass nil to assign no properties to the GameInstance.

[PropertyCollection](./propertycollection) gameInstanceUserProperties

The properties to assign to your GameInstanceUser. Pass nil to assign no properties to the GameInstanceUser.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

CreateRematch()

Creates a rematch of a GameInstance. Upon success, this will automatically update the internal list. If the GameInstance is not already finished, it will be finished and a leaderboard will be generated.

Returns void
Syntax
GameInstanceManager:CreateRematch( originalGameInstanceID, gameInstanceType, gameInstanceSubType, roomID, maxUsers, winningUserID, turnUserID, includeLeftGameUsers, rematchMessage, originalGameProps, origianlGameWinningUserProps, rematchGameProps, callbackFunc )
Parameters

number originalGameInstanceID

The ID of the original GameInstance we're creating a rematch from.

[string](#) gameInstanceType

The type of GameInstance to create. Potentially, a Game could have several types of GameInstance types within it. Type is limited to 16 characters.

[string](#) gameInstanceSubType

The subtype of the GameInstance that will be created. Potentially, a Game could have several subtypes within it. SubType is limited to 16 characters.

[number](#) roomID

The ID of the room the rematch GameInstance is created in. Pass in 0 for no room.

[number](#) maxUsers

The max number of users the GameInstance supports. Pass in 2 for a two player game.

[number](#) winningUserID

The ID of the User that has won the GameInstance.

[number](#) turnUserID

The ID of the User whose initial turn it is.

[boolean](#) includeLeftGameUsers

A boolean dictating whether users that have left the original game should be included in the rematched GameInstance.

[string](#) rematchMessage

The notification message to send to all other users that are a member of the rematched GameInstance. Pass "" to have no notification message sent.

[PropertyCollection](./propertycollection) originalGameProps

The final properties of the original GameInstance.

[PropertyCollection](./propertycollection) origianlGameWinningUserProps

The properties of the winning User of the original GameInstance.

[PropertyCollection](./propertycollection) rematchGameProps

The properties of the rematch GameInstance. Pass in nil to assign no properties to the rematched GameInstance.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

Delete()

Deletes a GameInstance. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:Delete( gameInstanceID, callbackFunc )
Parameters

number gameInstanceID

The ID of the GameInstance to delete.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

GetAll()

Gets all GameInstances. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:GetAll( userID, stateMask, maxCount, getGameInstanceProperties, friendsOnly, gameInstanceType, gameInstanceSubtype, callbackFunc )
Parameters

number userID

The ID of the User who must be a member of a GameInstance retrieved. Pass 0 to fetch all games regardless of membership within them.

[table](#) stateMask

A table containing the GameInstance States to retrieve. The following stateMask table members are examined:

waitingForPlayers Waiting for players to join the game.
inProgress Players are currently playing the game.
finished Game has been finished and a leaderboard was generated.
possibleRematch A rematched Game waiting for enough players to join.
forfeit Game was forfeited by a User.
Examples:
-- To get all GameInstances that are playable.
local stateMasks = { waitingForPlayers=true, inProgress=true };
-- To get all GameInstances regardless of State.
local stateMasks = { waitingForPlayers=true, inProgress=true, finished=true, possibleRematch=true, forfeit=true };
[number](#) maxCount

The maximum number of GameInstance to retrieve.

[boolean](#) getGameInstanceProperties

Set TRUE to retrieve the property collections of each game instance, FALSE to retrieve the instances without properties.

[boolean](#) friendsOnly

Set TRUE to retrieve only gamesin which you and your friends are joined in

[string](#) gameInstanceType

Set to retrieve only games with this type, pass nil to ignore.

[string](#) gameInstanceSubtype

Set to retrieve only games with this subtype, pass nil to ignore.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

GetAllInDuel()

Gets all the GameInstances in a duel. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:GetAllInDuel( gameInstanceDuelID, callbackFunc )
Parameters

number gameInstanceDuelID

The ID of the duel to retrieve all GameInstances for.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

Join()

Joins an existing GameInstance. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:Join( gameInstanceID, gameInstanceUserProperties, callbackFunc )
Parameters

number gameInstanceID

The ID of the specific GameInstance to join.

[PropertyCollection](./propertycollection) gameInstanceUserProperties

The properties to assign the User joining the GameInstance.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------

JoinRandom()

Joins a random existing GameInstance. Upon success, this will automatically update the internal list.

Returns void
Syntax
GameInstanceManager:JoinRandom( gameInstanceType, gameInstanceSubType, gameInstanceUserProperties, callbackFunc )
Parameters

string gameInstanceType

The type of GameInstance to join.

[string](#) gameInstanceSubType

The sub-type (if any) of GameInstance to join.

[TogetherPropertyCollection](./togetherpropertycollection) gameInstanceUserProperties

The properties to assign the User joining the GameInstance.

[function](#) callbackFunc

The function to call upon completion.

--------------------------------------------------------------------------------
⚠️ **GitHub.com Fallback** ⚠️