How to handle multiple room instances

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Post Reply
alex_h
Posts: 15
Joined: 27 Feb 2009, 12:56
Location: Bath, UK

How to handle multiple room instances

Post by alex_h »

Say I have a game 'Game A' that allows only 2 players. So player 1 arrives in the lobby, and decides to start a game by pressing a button.
This triggers a room to be created, called 'game_a' and player 1 joins that room.
Now player 2 arrives in the lobby, decides he also wants to play Game A and presses the button to do so. Great, he joins player 1 in the existing game room, I detect that there are now 2 players and so I start the game.
Now player 3 comes along into the lobby. He also wants to play Game A so he presses the button. I detect that all existing Game A rooms are full, which means I need to create a new one.

BUT - the name 'game_a' is already taken.

I could work around this by appending in integer to the room name, but I'd need a technique to ensure that the integer is unique - I'm not sure what would be the best way to do this? Appending to the room name would also make it problematic to try to retrieve rooms by name. I was intending to have all my 'Game A' rooms kept in a 'Game A Group' so that I can retrieve them all in one array - does that sound like a sensible approach? There must obviously be a standard way to deal with this problem - could anyone let me know what it is?

thanks a lot,

Alex
alex_h
Posts: 15
Joined: 27 Feb 2009, 12:56
Location: Bath, UK

Post by alex_h »

To answer my own question - I suppose that if I handle the game room creation via a Zone level extensions (as per the answer to my previous post) then I can just have an integer within my Zone extension class that is incremented each time a game room is created, and append this to the name. I guess this just means that I then avoid getting rooms by name from within my client side AS3 code, since I won't know what a room instance's name is unless I already have a reference to it.

Or am I getting this all horribly wrong...?
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Post by rjgtav »

Yes you are correct :-). Just remember than the int datatype, like all the other ones, has a limit, so when you reach that limit, you can simply start again from 0 :-)
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
alex_h
Posts: 15
Joined: 27 Feb 2009, 12:56
Location: Bath, UK

Post by alex_h »

thanks rjgtav! Yes, funnily enough I was just considering the int - max value issue. Thinking about it, as long as I make the looping occur at a sufficiently high number (more than the number of rooms likely to be open at once) then it is going to avoid any problems, it doesn't have to check for 2,147,483,647!
Post Reply