2014-02-09 51 views
2

我有這樣的代碼:谷歌玩就怎麼邀請玩家到一個房間

RoomConfig.Builder rtmConfigBuilder = makeBasicRoomConfigBuilder(); 
rtmConfigBuilder.addPlayersToInvite(opponentId); 
rtmConfigBuilder.setAutoMatchCriteria(null); 
mGamesClient.createRoom(rtmConfigBuilder.build()); 

但我得到的錯誤代碼這是STATUS_MULTIPLAYER_ERROR_INVALID_OPERATION

這多人操作是無效的,服務器拒絕它。檢查日誌以獲取更多信息。

我認爲這是因爲addPlayersToInvite方法,因爲我讀了Android文檔以下...

public RoomConfig.Builder addPlayersToInvite (String... playerIds) 

Add one or more player IDs to invite to the room. This should be set only when calling create(GoogleApiClient, RoomConfig) 

Parameters 
playerIds One or more player IDs to invite to the room. 
Returns 
The builder instance. 

注意它是如何說這應該只是調用創建(GoogleApiClient時設置, RoomConfig)但我不知道如何調用方法或做什麼。

所以我的問題基本上是這樣的:我有我邀請的玩家的ID,我現在想爲玩家和我創造一個房間。我怎樣才能做到這一點?

回答

4

我只是偶然發現了這一個,很抱歉挖這件事,但爲後人:

你可以不設置autoMatchCriteria爲null:

rtmConfigBuilder.setAutoMatchCriteria(null);

也,你居然不能設置minAutoMatchPlayers或maxAutoMatchPlayers設置爲0.

避免這種情況的最佳方法是進行零檢查,如果minAutoMatchPlayers或maxAutoMatchPlayers等於0,則不要使用setAutoMatchCriteria() :

final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); 
Bundle autoMatchCriteria = null; 

int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); 
int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0); 

if (minAutoMatchPlayers > 0) { 
    autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0); 
} else { 
    autoMatchCriteria = null; 
} 

RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this); 
if (autoMatchCriteria != null) { 
    roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria); 
} 
roomConfigBuilder.addPlayersToInvite(invitees); 
+1

在此日期,Multiplayer.EXTRA_PLAYERS已從API中刪除...當我找到新的常量,我將添加評論 – Arnaud

+1

更換應該是:Games.EXTRA_PLAYER_IDS – Arnaud

+1

編輯與API合作@Arnaud提到的變化 –