+ Reply to Thread
Results 1 to 6 of 6

Thread: when a user leaves a gameroom

  1. #1
    Junior Member
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    when a user leaves a gameroom

    using the tic tac toe as a starting point I have written a little multiplayer game using ES. It's almost there but I am not handling users leaving well, but I can't seem to find where it is.


    A simple enough question (I am sure I just keep looking straight past it) where is the code that handles a player leaving the game. I want to send a message to tell everyone who has left (using my game id)



    Ta

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Posts
    263
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    When user lefts room two ES events are fired:

    es.userListUpdated (following code is excerpt from ES documentation):


    [code]
    function userListUpdated(userList:Array, type:String, userReference:Object) {
    if (type == "all") {
    //The entire list is new
    buildUserList(userList);
    } else if (type == "userjoined") {
    //A user joined the room
    addUserToList(userReference);
    } else if (type == "userleft") {
    //A user left the room
    removeUserFromList(userReference);
    }
    }
    es.userListUpdated = userListUpdated;

    and second event:

    es.usersRenumbered


    [code]
    function usersRenumbered(userList:Array) {
    for (var i:Number = 0; i < userList.length; ++i) {
    trace(userList[i].AssignedNumber);
    }
    }
    es.usersRenumbered = usersRenumbered;

    I think es.userListUpdated event is in Your TicTacToe code in "game" frame (I write code for AS2, but they look similiar to AS1),

    hth,

    peter

  3. #3
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Peterblaze is right. But to tell you the exact code in the Tic Tac Toe example, here goes

    Code:
    function userListUpdated(userList, type, user) {
     if (user == gamePlayer0 || user == gamePlayer1) {
      //A game player left
      popup.gotoAndStop("Player Left");
     }
    }
    es.userListUpdated = userListUpdated;
    First a function is defined to receive the userListUpdate event. Then it is assigned as an event handler to that event (in the final line).



    Every time a user enters or leaves the room this function is called. When the function is called it is given useful information such as 'type' (meaning "userjoined", "userleft", etc), and a reference to the user in question. In the if statement we check to see if the user being referred to is a game player. If it is, then we make the popup window popup and show that the user has left the game.



    Of course there is a little more to it beause you had to store the variables called gamePlayer0 and gamePlayer1 earlier. So look in the code to see when and where that was done.
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  4. #4
    Junior Member
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    next problem

    there are room variables, but it doesn't look like there are game room variables. Am I right?

    My problem is this. My game starts with multiple players who get knocked out one at a time. generally the user then leaves the game room, but that means there is a space for someone to come in. I can't think of a way of stopping players joining a game room when the game is in progress but not full. a game room variable would do it, but I don't see them. A room variable is no use as there can be more than one game running at the same time in a room

    any ideas

  5. #5
    Electrotank jobem's Avatar
    Join Date
    Apr 2004
    Posts
    996
    Thanks
    0
    Thanked 24 Times in 17 Posts
    Hi Kiv_cg,

    Game rooms are still just rooms. You can still use the same methods to create/update room variables. You should be able to use them creatively to achieve what you are asking about.

    Also, you might find AssignedNumber to be useful. Every user in a game room (which is just a room with a few extra features) is assigned a unique number. You can find out a user's number through any user object, like so:

    es.getUser().AssignedNumber.value

    The above gets your own assigned number. If your number is 0, then you have been in the room longer than anyone else. It is common in 2 player games to allow usrs with assigned numbers of 1 and 0 to play the game. If a user has an assigned number of 2 or greater, then they are spectators.

    If you have users 0, 1, 2, 3, 4 and user 2 leaves, then 3 and 4 get renumbered to 2 and 3.
    ------
    Jobe Makar
    @jobemakar
    http://www.electrotank.com

    YouTube ElectroServer video tutorials
    http://www.youtube.com/user/ElectrotankInc

  6. #6
    Junior Member
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ta

    my first attempt at using this failed - it looked like the room variable was in the lobby rather than the game. I must have set it up at the wrong place.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts