togethergameinstance - TogetherGames/Public-Corona-Lua GitHub Wiki

TogetherGameInstance

Together::TogetherGameInstance

Overview

The GameInstance class represents a Together GameInstance or individual match.


Members

number GameInstanceID

The ID of the GameInstance.

string GameInstanceType

The type of GameInstance. ie (Board 3x3, Board 6x6, Board 9x9)

number GameInstanceDuelID

The ID of the duel the GameInstance belongs to. This is the ID of the first GameInstance in a line of rematches.

number CreatorUserID

The ID of the User that created the GameInstance.

number RoomID

The ID of the Room the GameInstance was created. If equal to 0, then the GameInstance wasn't created in a room.

number ChatRoomID

The ID of the ChatRoom associated with the GameInstance.

number SecondsSinceGameStarted

The number of seconds since the GameInstance was started.

number SecondsSinceLastModified

The number of seconds since the GameInstance was last modified.

number LastModifyTimestamp

A timestamp for when the GameInstance was last modified.

number RoundCount

The number of rounds the GameInstance has progressed through.

number TotalTurnCount

The total number of moves made.

boolean Active

A boolean indicating whether the GameInstance is active.

number State

The State of the GameInstance.

number UserCount

The number of users in the GameInstance.

number MaxUsers

The max number of users in the GameInstance.

number TurnUserID

The ID of the User whose turn it is. When 0, it is no User's turn. This will occur if first User makes their initial move and another possible User hasn't joined the GameInstance yet.

number TurnIndex

The index of whose turn it is.

number PlayCount

The number of times a GameInstance has been played in the duel. This value will be 1 for the initial GameInstance. 2 for the second GameInstance in the duel. 3 for the third GameInstance in the duel.

number WinningUserID

The ID of the User that has won the GameInstance. When 0, there is no winner of the GameInstance.

boolean IsUserMemberOf

A boolean indicating whether the logged in User is a member of the GameInstance.

number LeaderboardID

The ID of the Leaderboard associated with the GameInstance.

PropertyCollection Properties

A property collection containing all custom properties for the GameInstance.

table GameInstanceUsers

Contains all the GameInstanceUsers that are playing the GameInstance.


Methods


AddGameInstanceUser()

Adds a GameInstanceUser to the manager internally without persistence.

Note
This method is deprecated

Returns void
Syntax
TogetherGameInstance:AddGameInstanceUser( gameInstanceUser )
Parameters

TogetherGameInstanceUser gameInstanceUser

Instance of the GameInstanceUser to add to the internal list

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

FindGameInstanceUserByUserID()

Finds the GameInstanceUser with the specified UserID if it exists, otherwise returns nil.

Syntax
TogetherGameInstance:FindGameInstanceUserByUserID( userID )
Parameters

number userID

The ID of the User to find

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

FindGameInstanceUserByGameInstanceUserID()

Finds the GameInstanceUser with the specified GameInstanceUserID if it exists, otherwise returns nil.

Syntax
TogetherGameInstance:FindGameInstanceUserByGameInstanceUserID( gameInstanceUserID )
Parameters

number gameInstanceUserID

The ID of the GameInstanceUser to find

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

GetGameInstanceUserCount()

Gets the number of GameInstanceUsers currently managed internally.

Returns number
Syntax
TogetherGameInstance:GetGameInstanceUserCount(  )

GetGameInstanceUser()

Gets the GameInstanceUser at the specified index if it exists, otherwise returns nil.

Syntax
TogetherGameInstance:GetGameInstanceUser( index )
Parameters

number index

The index of the GameInstanceUser to find

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

GetTurnIndexForUser()

Gets the TurnIndex for a particular User. Turn indexes are base 0. Returns -1 if the user is not found.

Returns number
Syntax
TogetherGameInstance:GetTurnIndexForUser( userID )
Parameters

number userID

The ID of the User we're interested in getting the TurnIndex for

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

IndexOfGameInstanceUser()

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

Returns number
Syntax
TogetherGameInstance:IndexOfGameInstanceUser( gameInstanceUser )
Parameters

TogetherGameInstanceUser gameInstanceUser

Instance of the GameInstanceUser to find the index of

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

IndexOfGameInstanceUserByUserID()

Returns the index of the GameInstanceUser with the specified UserID if it exists, otherwise returns -1.

Returns number
Syntax
TogetherGameInstance:IndexOfGameInstanceUserByUserID( userID )
Parameters

number userID

The ID of the User to find the index of

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

IndexOfGameInstanceUserByGameInstanceUserID()

Returns the index of the GameInstanceUser with the specified GameInstanceUserID if it exists, otherwise returns -1.

Returns number
Syntax
TogetherGameInstance:IndexOfGameInstanceUserByGameInstanceUserID( gameInstanceUserID )
Parameters

number gameInstanceUserID

The ID of the GameInstanceUser to find the index of

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

RemoveGameInstanceUser()

Removes a GameInstanceUser from the internally managed list. This does not delete the user from the instance persistently.

Note
This method is deprecated

Returns void
Syntax
TogetherGameInstance:RemoveGameInstanceUser( index )
Parameters

number index

The index of the GameInstanceUser to be removed internally

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

GetDetails()

Gets the GameInstance's details. This message should be called whenever it is necessary to get the latest state of a GameInstance. Internally, this method passes the GameInstance's LastModifyTimestamp to the server. If the LastModifyTimestamp is the same value on the server, a "No Change" error will be returned. If you do not wish this behavior, set LastModifyTimestamp on the GameInstance object to 0 before calling this method and full details will always be returned. Upon success, this will automatically update the internal data.

Returns void
Syntax
TogetherGameInstance:GetDetails( gameInstanceID, callbackFunc )
Parameters

number gameInstanceID

The ID of the GameInstance to retrieve details for

[function](#) callbackFunc

The function to call upon completion.

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

Finish()

Finishes a GameInstance. This message should be called whenever a GameInstance is finished. The State of the GameInstance will change to (4 = GAME_STATE_FINISHED). A Leaderboard will be generated for the GameInstance. Upon success this will automatically update the internal data.

Returns void
Syntax
TogetherGameInstance:Finish( winningUserID, callbackFunc )
Parameters

number winningUserID

The ID of the User that has won the GameInstance. Pass in 0 if there was no winner.

[function](#) callbackFunc

The function to call upon completion.

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

Forfeit()

Forfeits a GameInstance. This message should be called whenever a GameInstance is forfeited by a User. The State of the GameInstance will change to (16 = GAME_STATE_FORFEIT). Upon success, this will automatically update the internal data.

Returns void
Syntax
TogetherGameInstance:Forfeit( callbackFunc )
Parameters

function callbackFunc

The function to call upon completion.

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

InviteUser()

Invites a User to a GameInstance. Upon success, this will automatically update the internal data.

Returns void
Syntax
TogetherGameInstance:InviteUser( inviteeUserID, inviteeSocialType, inviteeSocialID, gameUserProperties, notificationMessage, callbackFunc )
Parameters

number inviteeUserID

The ID of the Together User to invite to the GameInstance. Pass in 0 when inviting an external (Facebook) friend.

[string](#) inviteeSocialType

The type of social network we're inviting a friend from. Pass "FB" for Facebook. Pass "" when passing a valid Together User.

[string](#) inviteeSocialID

The ID of the external (Facebook) friend we're inviting. For a Facebook friend, pass the friend's FacebookID. Pass "" when passing a valid Together User.

[PropertyCollection](./propertycollection) gameUserProperties

A PropertyCollection to associate with the GameInstanceUser that gets created, or nil to attach no properties.

[string](#) notificationMessage

The notification message to send to the Together User. Pass "" to prevent sending a notification.

[function](#) callbackFunc

The function to call upon completion.

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

Leave()

Leaves this GameInstance. Upon success, this will automatically update the internal data.

Returns void
Syntax
TogetherGameInstance:Leave( callbackFunc )
Parameters

function callbackFunc

The function to call upon completion.

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

MakeMove()

Makes a move in the GameInstance with optional turn index updates. Turn indexes are base 0. Upon success, this will automatically update the internal data. The following GameInstance members are sent to the server when this method is called.

  • GameInstanceID: The ID of the GameInstance we're making a move in.
  • TurnIndex: The current Index of which User whose turn it is.
  • NewTurnUserID: The UserID of the User whose turn it should be. Pass in 0 to
    assign the next turn to no one. The only time 0 should be passed
    is if another User can join the game and the game is waiting. This
    is because whenever a User joins a game and the current TurnUserID is
    unassigned, turn is immediately assigned to the new user.
  • NewTurnIndex: The index of the next User to assign the turn to. For a two player
    GameInstance, the TurnIndex should either be 0 or 1.
  • GameInstanceUserID: The current GameInstanceUserID whose turn it is.
  • GameProps: The GameInstance.Properties member representing the properties for the GameInstance.
  • GameUserProps: The Properties of the GameInstanceUser that is making the move.
Returns void
Syntax
TogetherGameInstance:MakeMove( callbackFunc )
Parameters

function callbackFunc

The function to call upon completion.

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

Modify()

Modifies the GameInstance. Upon success, this will automatically update the internal data. The following GameInstance members are sent to the server when this method is called:

  • GameInstanceID: The ID of the GameInstance we're making a move in.
  • Active: The active boolean on the GameInstance.
  • TurnUserID: The UserID of the User whose turn it should be. Pass in 0 to assign the next turn to no one.
  • TurnIndex: The Index of the User whose turn it is.
  • GameProps: The GameInstance.Properties member representing the properties for the GameInstance.
  • State: The State of the GameInstance.
GAME_STATE_WAITING_FOR_PLAYERS =1 Waiting for players to join the game.
GAME_STATE_IN_PROGRESS =2 Players are currently playing the game.
GAME_STATE_FINISHED =4 Game has been finished and a leaderboard was generated.
GAME_STATE_POSSIBLE_REMATCH =8 A rematched Game waiting for enough players to join.
GAME_STATE_FORFEIT =16 Game was forfeited by a User.
Returns void
Syntax
TogetherGameInstance:Modify( indexOfUserToModify, callbackFunc )
Parameters

number indexOfUserToModify

The index of the GameInstanceUser to modify as well. Pass -1 to modify no GameInstanceUser.

[function](#) callbackFunc

The function to call upon completion.

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