Here is console output.
I/Corona (19967): isLoggedin true
I/Corona (19967): was logged in to Google Play GS
I/Corona (19967): nil nil nil
I/Corona (19967): 1
I/Corona (19967): 1
I/Corona (19967): selected
I/Corona (19967): select Players!
I/Corona (19967): ROOM CREATED room ID !!!ChoKCQio8ZXcpAUQAhABGAAg____________ARCpnt2fjLmZ72E
I/Corona (19967): myWaitingRoom Call
I/Corona (19967): room listener call back
I/Corona (19967): ChoKCQio8ZXcpAUQAhABGAAg____________ARCpnt2fjLmZ72E
I/Corona (19967): p_CJP7xq7R9KDtJhAB
I/Corona (19967): false
I/Corona (19967): peerAcceptedInvitation
I/Corona (19967): room listener call back
I/Corona (19967): ChoKCQio8ZXcpAUQAhABGAAg____________ARCpnt2fjLmZ72E
I/Corona (19967): p_CJP7xq7R9KDtJhAB
I/Corona (19967): false
I/Corona (19967): connectedRoom
I/Corona (19967): waitingRoom
I/Corona (19967): p_CJP7xq7R9KDtJhAB nil nil
I/Corona (19967): ChoKCQio8ZXcpAUQAhABGAAg____________ARCpnt2fjLmZ72E
I/Corona (19967): start
I/Corona (19967): false
I/Corona (19967): waiting room Shown!!!
I/Corona (19967): gameNetworkSendMessageCallBack
I/Corona (19967): messageReceived
I/Corona (19967): nil nil nil
I/Corona (19967): nil
I/Corona (19967): nil
I/Corona (19967): nil
I/Corona (19967): message Sent
Here is the Code and The user is logged in at this point.
local isLoggedIn = gameNetwork.request(“isConnected”)
print("isLoggedin "…tostring(isLoggedIn))
if isLoggedIn == false then
print(“was not logged in to Google Play GS”)
gameNetwork.init( “google”, gpgsInitCallback )
else
print(“was logged in to Google Play GS”)
local player2
local createdRoom
local localPlayer
local function gameNetworkReceiveMessage( event )
print(“gameNetworkReceiveMessage”)
print( event.data.participantID )
print( event.data.message )
local function onAlertComplete( event )
if event.action == “clicked” then
local i = event.index
if i == 1 then
– Do nothing; dialog will simply dismiss
end
end
end
– Show alert with two buttons
local messageAlert = native.showAlert( “DIGI-S1 Online”, event.data.message, { “OK” }, onAlertComplete )
end
gameNetwork.request( “setMessageReceivedListener”,
{
listener = gameNetworkReceiveMessage
}
)
local function gameNetworkSendMessageCallBack(event)
print(“gameNetworkSendMessageCallBack”)
print( event.type ) --“waitingRoom”
print( event.data[1], event.data[2], event.data[3] ) --participant IDs
print( event.data.message )
print( event.data.phase )
print( event.data.isError )
print(“message Sent”)
end
local function gameNetworkSendMessage(thisMessage, player_ID)
gameNetwork.request( “sendMessage”,
{
roomID = createdRoom,
playerIDs =
{
player_ID ,
},
message = thisMessage,
reliable = true,
listener = gameNetworkSendMessageCallBack
}
)
end
local function myWaitingRoom()
print(“myWaitingRoom Call”)
local function waitingRoomListener( event )
print( event.type ) --“waitingRoom”
print( event.data[1], event.data[2], event.data[3] ) --participant IDs
print( event.data.roomID )
print( event.data.phase )
print( event.data.isError )
print(“waiting room Shown!!!”)
gameNetworkSendMessage(“Hopefully you just get this!!”, event.data[1])
end
gameNetwork.show( “waitingRoom”,
{
roomID = createdRoom,
minPlayers = 4,
listener = waitingRoomListener
}
)
end
local numCount = 0
local function requestRoomCallback( event )
print( “ROOM CREATED room ID !!!”…tostring(event.data.roomID) )
createdRoom = event.data.roomID
numCount = numCount + 1
if numCount == 1 then
myWaitingRoom()
local function roomListenerCallback( event )
print(“room listener call back”)
print( event.data.roomID )
print( event.data[1] )
print(event.data.isError)
print(event.type)
end
gameNetwork.request( “setRoomListener”,
{
listener = roomListenerCallback
}
)
end
end
local numCount2 = 0
local function selectPlayersListener( event )
print( event.data[1], event.data[2], event.data[3] ) --selected player IDs
print( event.data.minAutoMatchPlayers )
print( event.data.maxAutoMatchPlayers )
print( event.data.phase )
player2 = event.data[1]
print(“select Players!”)
numCount2 = numCount2 + 1
if numCount2 == 1 then
gameNetwork.request( “createRoom”,
{
playerIDs = {
player2,
},
maxAutoMatchPlayers = event.data.maxAutoMatchPlayers, --optional, defaults to 0
minAutoMatchPlayers = event.data.minAutoMatchPlayers, --optional, defaults to 0
listener = requestRoomCallback --including this will override any listener set in
}
)
end
end
gameNetwork.show( “selectPlayers”,
{
minPlayers = 1,
maxPlayers = 1,
listener = selectPlayersListener
}
)
Super Hard to read this way. I am also attaching a file.
Code Flow:
-
Set Up Set Message Received Listener
-
Show Select Players
-
In Select Players call back I Create a Room
-
In Create Room call back I call my own function myWaitingRoom()
-
In myWaitingRoom() i call Set Room Listener
-
In Set Room Listener call back if the Room is a “connectedRoom” then show Waiting Room
-
In Waiting Room Listener call back I call Load Players and Send Message
Problems:
When I call Select Players the user picks Auto Match or finds friends on google+ and by the Corona Documentation in its call back I should get an ID. It is always nil.
So when I create the room it is being passed nil for the player ID’s but I creates the room anyway.
I can get the participantID when I call the Waiting Room function and that is what I use to try to send a message. But my Message Received Listener is either not working or I am not getting the right ID’s??
In the console my Set Room Listener says that the room does in fact get connected. Why would I not be able to send any message!! This is killing me!!
The Send Message call back is being called! The call back is saying that the message was received! Why is my Message Received Listener not working!!!