Navigation

    Colyseus
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. deadwind88
    D

    deadwind88

    @deadwind88

    Chat Follow Unfollow
    0
    Reputation
    2
    Posts
    1210
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with deadwind88
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    deadwind88 Follow

    Posts made by deadwind88

    RE: How to send message to client by client ID

    @endel Thank you so much.
    But i still not understand how to send the code to player who is invited.
    For example:
    Player A login, and see this lists
    B, C, D
    A want to invite C to duel, A send a message to Server "Hey, I want to make a duel with C"
    I don't know how to make Server to send message to C "Hey A want to make a dule with C" and C can accept or not.
    This is my code

    // When a client sends a message
        onMessage (client, message) {
            switch (message.action) {
                //A send request to invite C to make a duel
                case 'request_dule':
                    let guestId = message.data.guest_id;
                    let guest = this.state.players[guestId];
                    //find a client has id equal with C's client id
                    for (let i = 0; i < this.clients.length; i++) {
                        if (this.clients[i].id == guest.client_Id) {
                            //send request to C's client and wait C accepting
                            this.send(this.clients[i], {action: 'request_dule', data: {host: client.id}});
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    

    Looking forward your advice. Thanks

    posted in Questions & Help •
    How to send message to client by client ID

    Hi everyone.
    I am new in Colyseus. I am learning to create a simple game.
    All players will join only one room - Lobby
    Then choose one in other players to invite to dule ( 1 vs 1 game)
    If the invited player accepts, other players will see this two players are marked "Duling"
    Then this two players will moved to Game screen to dule.
    But i have problem in two steps

    1. How to send message to chosen player?
      I am going to use foreach to check all clients in the room with chosen player client ID. But i think it is bad solution.
    2. I don't know one client can connect to many room or not.
      Because as i understood, these two players will be moved to Game room that only has 2 players. But i still want to keep their name and status in Lobby screen.
      What is best solution?
      Thanks you so much.
    posted in Questions & Help •