Forum Multiplayer NULL on CreateJoinRoom

Discussion and help relating to the PlayerIO Multiplayer API.

NULL on CreateJoinRoom

Postby Alex1339 » March 21st, 2017, 7:07 pm

Hy! I need help! After createjoinroom first time, connection from delegate is null. after second time the conection receives proper value.
Why connection does not receive value for the first time?
Alex1339
 
Posts: 4
Joined: December 18th, 2016, 8:58 pm

Re: NULL on CreateJoinRoom

Postby Henrik » March 21st, 2017, 9:16 pm

Hey Alex,

Can you show us a sample of the code you are using?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: NULL on CreateJoinRoom

Postby Alex1339 » March 22nd, 2017, 7:36 am

Code: Select all
clientGame.Multiplayer.CreateJoinRoom(rooms[j].Id.ToString(), "Public", true, null, null,
                        delegate (Connection conn)
                        {
                                connect = conn;
                                connect.OnMessage += ConnectOnMessage;
                                Debug.Log("SuccesJoin " + connect.ToString());
                            }
                        },
                        delegate
                        {
                        });
                    Global.servConnection = connect;
Alex1339
 
Posts: 4
Joined: December 18th, 2016, 8:58 pm

Re: NULL on CreateJoinRoom

Postby Henrik » March 22nd, 2017, 8:55 am

That's not gonna work, because the code inside the success callback is going to execute *after* the statement where you set Global.servConnection, so you're setting it to null. If you put a Debug.Log statement there, you'll see that they execute in that order.

You'll have to set Global.servConnection inside the callback, and signal your main thread that it's set now, or whatever you need.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: NULL on CreateJoinRoom

Postby Alex1339 » March 22nd, 2017, 9:41 am

It means that i need put Global.serConnection in success callback?
Alex1339
 
Posts: 4
Joined: December 18th, 2016, 8:58 pm

Re: NULL on CreateJoinRoom

Postby aseemgarg321 » March 23rd, 2017, 6:32 am

Yes.. And also any kind of Action/Function with this "connection" need to be done only after you have received Successful Call back..

Thanks,
Aseem
aseemgarg321
 
Posts: 104
Joined: March 28th, 2015, 9:54 am

Re: NULL on CreateJoinRoom

Postby Alex1339 » March 23rd, 2017, 7:39 am

aseemgarg321 wrote:Yes.. And also any kind of Action/Function with this "connection" need to be done only after you have received Successful Call back..

Thanks,
Aseem

Thank you very much! ;)
Alex1339
 
Posts: 4
Joined: December 18th, 2016, 8:58 pm


Return to Multiplayer



cron