togethergameinstance - TogetherGames/Public-Corona-Lua GitHub Wiki
Together::TogetherGameInstance
The GameInstance class represents a Together GameInstance or individual match.
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.
Adds a GameInstanceUser to the manager internally without persistence.
Note
This method is deprecated
Returns void
TogetherGameInstance:AddGameInstanceUser( gameInstanceUser )
TogetherGameInstanceUser gameInstanceUser
Instance of the GameInstanceUser to add to the internal list
--------------------------------------------------------------------------------Finds the GameInstanceUser with the specified UserID if it exists, otherwise returns nil.
Returns TogetherGameInstanceUser
TogetherGameInstance:FindGameInstanceUserByUserID( userID )
number userID
The ID of the User to find
--------------------------------------------------------------------------------Finds the GameInstanceUser with the specified GameInstanceUserID if it exists, otherwise returns nil.
Returns TogetherGameInstanceUser
TogetherGameInstance:FindGameInstanceUserByGameInstanceUserID( gameInstanceUserID )
number gameInstanceUserID
The ID of the GameInstanceUser to find
--------------------------------------------------------------------------------Gets the number of GameInstanceUsers currently managed internally.
Returns number
TogetherGameInstance:GetGameInstanceUserCount( )
Gets the GameInstanceUser at the specified index if it exists, otherwise returns nil.
Returns TogetherGameInstanceUser
TogetherGameInstance:GetGameInstanceUser( index )
number index
The index of the GameInstanceUser to find
--------------------------------------------------------------------------------Gets the TurnIndex for a particular User. Turn indexes are base 0. Returns -1 if the user is not found.
Returns number
TogetherGameInstance:GetTurnIndexForUser( userID )
number userID
The ID of the User we're interested in getting the TurnIndex for
--------------------------------------------------------------------------------Returns the index of the specified GameInstanceUser if it exists, otherwise returns nil.
Returns number
TogetherGameInstance:IndexOfGameInstanceUser( gameInstanceUser )
TogetherGameInstanceUser gameInstanceUser
Instance of the GameInstanceUser to find the index of
--------------------------------------------------------------------------------Returns the index of the GameInstanceUser with the specified UserID if it exists, otherwise returns -1.
Returns number
TogetherGameInstance:IndexOfGameInstanceUserByUserID( userID )
number userID
The ID of the User to find the index of
--------------------------------------------------------------------------------Returns the index of the GameInstanceUser with the specified GameInstanceUserID if it exists, otherwise returns -1.
Returns number
TogetherGameInstance:IndexOfGameInstanceUserByGameInstanceUserID( gameInstanceUserID )
number gameInstanceUserID
The ID of the GameInstanceUser to find the index of
--------------------------------------------------------------------------------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
TogetherGameInstance:RemoveGameInstanceUser( index )
number index
The index of the GameInstanceUser to be removed internally
--------------------------------------------------------------------------------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
TogetherGameInstance:GetDetails( gameInstanceID, callbackFunc )
number gameInstanceID
The ID of the GameInstance to retrieve details for
[function](#) callbackFuncThe function to call upon completion.
--------------------------------------------------------------------------------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
TogetherGameInstance:Finish( winningUserID, callbackFunc )
number winningUserID
The ID of the User that has won the GameInstance. Pass in 0 if there was no winner.
[function](#) callbackFuncThe function to call upon completion.
--------------------------------------------------------------------------------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
TogetherGameInstance:Forfeit( callbackFunc )
function callbackFunc
The function to call upon completion.
--------------------------------------------------------------------------------Invites a User to a GameInstance. Upon success, this will automatically update the internal data.
Returns void
TogetherGameInstance:InviteUser( inviteeUserID, inviteeSocialType, inviteeSocialID, gameUserProperties, notificationMessage, callbackFunc )
number inviteeUserID
The ID of the Together User to invite to the GameInstance. Pass in 0 when inviting an external (Facebook) friend.
[string](#) inviteeSocialTypeThe type of social network we're inviting a friend from. Pass "FB" for Facebook. Pass "" when passing a valid Together User.
[string](#) inviteeSocialIDThe 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) gameUserPropertiesA PropertyCollection to associate with the GameInstanceUser that gets created, or nil to attach no properties.
[string](#) notificationMessageThe notification message to send to the Together User. Pass "" to prevent sending a notification.
[function](#) callbackFuncThe function to call upon completion.
--------------------------------------------------------------------------------Leaves this GameInstance. Upon success, this will automatically update the internal data.
Returns void
TogetherGameInstance:Leave( callbackFunc )
function callbackFunc
The function to call upon completion.
--------------------------------------------------------------------------------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
TogetherGameInstance:MakeMove( callbackFunc )
function callbackFunc
The function to call upon completion.
--------------------------------------------------------------------------------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
TogetherGameInstance:Modify( indexOfUserToModify, callbackFunc )
number indexOfUserToModify
The index of the GameInstanceUser to modify as well. Pass -1 to modify no GameInstanceUser.
[function](#) callbackFuncThe function to call upon completion.
--------------------------------------------------------------------------------