Hi, i don’t know if someone faced this issue, i saved an object ‘equipped’ with keys like “HELM” “WEAPON” etc each contains “id” “name” “damage” “protection” “obj” etc the saving on firebase is made, but when i try to get back that values i’m struggling to rebild the right construct of the variable, any of you can help me figuring the right coding for server.js and client side network.js…or just give me a documentation reference that i can study
Hi @ayrin,
I’ve been doing some work with talking between a colyseus server and a playcanvas client. Could you elaborate a little on the issues that you’re having?
At first, I thought you were having trouble accessing your firebase app, which had leaning toward CORS, but upon rereading, it looks like you’re just having trouble constructing the response in Colyseus?
Are you getting any errors in any of your consoles (node or browser)? What’s the expected response structure and what’s the structure you’re currently receiving?
This information will make it a lot easier to assist.
Hi @eproasim , I have overcome lot of hurdles but i’m struck coz i have saved this variable that is meant to save (and recover) the equipped itens of the player, i was able to save it but when i have to retrieve it (since it’s not an array) i have some troubles. since i can’t do this
class Equipped extends Schema {
constructor() {
super();
this.HELM = null;
this.ARMOUR = null;
this.WEAPON = null;
this.WEAPON2 = null;
this.SHIELD = null;
this.SHIELD2 = null;
this.ITEM = null;
}
}
type("number")(Equipped.prototype, "HELM");
type("number")(Equipped.prototype, "ARMOUR");
type("number")(Equipped.prototype, "WEAPON");
type("number")(Equipped.prototype, "WEAPON2");
type("number")(Equipped.prototype, "SHIELD");
type("number")(Equipped.prototype, "SHIELD2");
type("number")(Equipped.prototype, "ITEM");
because each object has many variables inside so number or string can’t be used.
neither this works
if (data.equipped) {
Object.keys(data.equipped).forEach(slot => {
player.equipped[slot] = data.equipped[slot] || 0;
});
}
so i’m quite at a loss
So, just to make sure, are you wanting to to have these Equipped objects as part of the Room Schema? I understand your issue with the Schema not allowing nullable types. That is discussed in this issue on the Colyseus repo:
Given that nullable type are impossible. Have you considered making an “empty” type item that’s equipped when nothing is supposed to be there. That would make it possible for you to use strings or integers. It could be something like -1 or “empty”. Then (only using your example because there’s still a lot of missing background information) you could make a valid schema like this:
for integers:
export class Equipped extends Schema {
@type("number") HELM = -1;
@type("number") ARMOUR = -1;
@type("number") WEAPON = -1;
@type("number") WEAPON2 = -1;
@type("number") SHIELD = -1;
@type("number") SHIELD2 = -1;
@type("number") ITEM = -1;
}
for strings:
export class Equipped extends Schema {
@type("string") HELM = "empty";
@type("string") ARMOUR = "empty";
@type("string") WEAPON = "empty";
@type("string") WEAPON2 = "empty";
@type("string") SHIELD = "empty";
@type("string") SHIELD2 = "empty";
@type("string") ITEM = "empty";
}
And then, I assume you’re attaching them to a player map in your room schema, looking something like this: (?)
export class Player extends Schema {
// ... other player properties
@type( Equipped ) equipped = new Equipped();
}
export class RoomState extends Schema {
//... other room state properties
@type({map: Player}) players = new MapSchema<Player>();
}
These examples are assuming you’re working with the TypeScript quickstart server from Colyseus.
I hope this is helpful.