Forum Multiplayer Error with createRoom()

Discussion and help relating to the PlayerIO Multiplayer API.

Error with createRoom()

Postby mattdown » November 7th, 2010, 1:35 am

my code:

Code: Select all
client.multiplayer.createRoom("test", "NewGame", true, {}, handleJoin, handleError);


seems to keep giving this error:

TypeError: Error #1034: Type Coercion failed: cannot convert "test" to playerio.Connection.
at Function/<anonymous>()
at Function/<anonymous>()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Does this method join the room as well as creating it? I'm a bit confused.

I'm trying to develop a two player game right now. What's the best way of managing the rooms such that the first player to join creates a new room with a random ID and another player joins that room or creates a new one if that one is full. Simple problem I know, but what's the best solution? I tried createJoinRoom() but using 'null' as the first parameter just joins the room that's already open.

Cheers,
Matt
mattdown
Paid Member
 
Posts: 12
Joined: October 27th, 2010, 11:20 am

Re: Error with createRoom()

Postby Oliver » November 9th, 2010, 1:58 pm

Hey Matt,

createRoom() doesn't join the room, it just returns the room id of the room that was created. If you want to create a room and join it immidately, you have to use createJoinRoom(), which creates and joins a room if it does not exist, or joins it if it already exists.

To solve your requirements, you'll have to involve listRooms() and createJoinRoom(), and possible the AllowUserJoin() method on the serverside.

Something like this:
- use listRooms to find a room with one waiting player
- if you find a room with just one waiting player, join it,
- otherwise, use createJoinRoom (w/ room id=null) to create and join a new room.

Now, in extreme cases (loads of players online), you might have two players joining the same room at the same time, and this is where you'd use AllowUserJoin() on the serverside to only allow a join if there aren't already two players in the room. Then on the clientside, if you get an error, you can run through the steps from the top again.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Error with createRoom()

Postby TharosTheDragon » February 18th, 2013, 6:27 am

This is just what I was looking for, thanks.

I was confused because all the documentation says that setting the room id to null will generate a random room id. This seems to imply that there's a chance that the randomly generated room id will be the id of a room that already exists. However, I've found several places in the forums where administrators have said that setting the room id to null will create a new room. I just thought I'd check to make sure. Does calling createJoinRoom with a null room id have a chance of generating an id that's in use?
TharosTheDragon
 
Posts: 17
Joined: February 6th, 2013, 7:56 am

Re: Error with createRoom()

Postby Henrik » February 18th, 2013, 11:22 am

TharosTheDragon wrote:Does calling createJoinRoom with a null room id have a chance of generating an id that's in use?

No.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Error with createRoom()

Postby Emalton » December 25th, 2017, 4:49 am

What is the purpose of createRoom?
Emalton
 
Posts: 86
Joined: June 28th, 2013, 3:49 am


Return to Multiplayer



cron