Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. zack1991
Z

zack1991

@zack1991

Chat Follow Unfollow
0
Reputation
6
Posts
1.1k
Profile views
0
Followers
0
Following
Joined 8 Mar 2022, 05:04 Last Online 8 Feb 2023, 13:36

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

Posts made by zack1991

RE: Deprecate a field of Schema in javascript

Hi Coco,

Thanks for your reply, actually i need information about @deprecated.

Live Version 1 :-

import { Schema, type, deprecated } from "@colyseus/schema";

class MyState extends Schema {
@type("string") myField: string;
}

LIVE VERSION 2 :-

import { Schema, type, deprecated } from "@colyseus/schema";

class MyState extends Schema {

// Flag field as deprecated.
@deprecated() @type("string") myField: string;

// To allow your server to play nicely with multiple client-side versions.
@type("string") newField: string;

}

How can achieve this in javascript.

posted in Questions & Help • 10 Jan 2023, 11:29
Deprecate a field of Schema in javascript

Hi,
How can i deprecate a field of schema in javascript. In colyseus doc only typescript format is given.

posted in Questions & Help • 10 Jan 2023, 05:45
How can i call a command inside setTimeout

Hi, i am trying to call a command inside setTimeout which is also inside a command. I am sharing my code. The command inside setTimeout is not getting called, can you please help me how can i do that.

class DecideCurrentTurn extends command.Command {

execute( {diceData}) {
    //set currentTurn according to diceVal
    const result = diceData.reduce((dice1, dice2) => dice1.diceVal > dice2.diceVal ? dice1 : dice2);
    this.state.currentTurn = result.sessionId;
    
    this.clock.setTimeout(() => {
        return [new SetInitialDiceRoll().setPayload({diceData})];
    }, 1000);
}

}

posted in Questions & Help • 24 Mar 2022, 12:43
RE: Create New Room according to specified condition(solved)

Hi COCO,
Thanks for your reply, after 2 players are joined the room it will be available in pool so when a 3rd player try to join the room this room will be available to join. My requirement is when 2 players are joined then room should not be available in the pool and when 3rd player try to join the room a new room should be created. I have tried to lock the room after 2 players are joined so it will be removed from the pool which is fine but when i am trying to join this room as spectator from my lobbyroom using matchmaker api i got error message "The room is locked". Can you please help how can i handle this scenario. If you share some code it will be better for me to understand.

Thanks.

posted in Questions & Help • 10 Mar 2022, 11:56
Create New Room according to specified condition(solved)

I am using colyseus version 0.14.18. My requirement is after 2 players are joined the game then no other players can join that room while spectators can. How can i achieve this. Please help. I am sharing my code below.

class MyRoom extends colyseus.Room {
maxClinets = 50;

onCreate(options) {
    console.log("New Room created!", options);
    this.dispatcher = new command.Dispatcher(this);
    this.setState(new GameState());

    // Broadcast chat messages
    this.onMessage('chat', (client, message) => {
        this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name}: ${message}`});
    });

    this.dispatcher.dispatch(new BoardCommand.SetupBoard(), {});
}

onJoin(client, options) {
    this.dispatcher.dispatch(new PlayerCommand.OnJoin(), {sessionId: client.sessionId, playerData: options});
    this.broadcast("chat", {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} Joined`});

    //if 2 players joined then roll 1 dices for each player for turn
    if (this.state.players.size === 2) {

    }
}

async onLeave(client, consented) {
    // Broadcast leaving to room chat
    this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} disconnected`}, {except: client});
    console.log(`${this.state.players[client.sessionId].name} disconnected`);

    this.dispatcher.dispatch(new PlayerCommand.OnLeave(), {
        sessionId: client.sessionId,
        consented
    });

    // Player has lost connection and player is not spectator
    if (!consented && !this.state.players.get(client.sessionId).isSpectator) {
        try {
            await this.allowReconnection(client, 60);

            // Regains connection
            this.dispatcher.dispatch(new PlayerCommand.OnConnect(), {sessionId: client.sessionId});
            this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} has returned`});
            console.log(`${this.state.players[client.sessionId].name} has returned!`);
        } catch (exc) {
            // ...or times out
            this.dispatcher.dispatch(new PlayerCommand.OnReconnectTimeout(), {sessionId: client.sessionId});
        }
    }
}

onDispose() {
    console.log("Dispose BackgammonRoom");
    this.dispatcher.stop();
}

}

module.exports = {MyRoom};

posted in Questions & Help • 8 Mar 2022, 06:22

© 2023 Endel Dreyer