Found solution here.
Posts made by shophk
Hi, I'm testing cocos creator (Javascript) to connect to Colyseus server, any known examples shown how to use javascript client through cocos creator to connect to Colyseus server? Or advise how I should go about doing this?
@endel Yes, I would like to limit the number of rooms. I want to have the first 10 rooms to have bonus or special effects.
after the first 10 rooms, users will get put into another registered room.
So in a way, yes, I want to limit the number of rooms the server can spawn base on some criteria.
Hi,
I'm trying to find a way to set the number of rooms.
My code trace has led me to believe I can make changes here:
MatchMaker.prototype.create = function (roomName, clientOptions) { ...}
Change the function so that it checks some flag to decided whether a room should be returned.
My question: I am not suppose to change the code for the files in the Colyseus folder right? What would be the recommended actions or approach to take for handling what I want to do?
My solution to this is using JSON.stringify to parse the variable into a string. I'm hoping there is a better solution.
var roomname = {
roomName : 'a room passed as string'
}
var text = JSON.stringify (roomname);
console.log("stringify text: " + text);
this.state.roomname.push (text);
I have the following:
class ChatRoom extends Room {
constructor () {
super();
this.setState({
players: {},
messages: [],
roomname: []
});
}
In onJoin(client)...
//it works if I do this, I can retrieve the string in Unity.
this.state.roomname.push ('a room passed as string');
var roomname = {
roomName : 'a room passed as string'
}
//it doesn't work if I do this, I get a '1' as the result when i try to read the object.
this.state.roomname.push (roomname);
How do I push a variable?
I'm thinking like in socket.io . I can send currentUser, in Unity I use a Json deserialiser to read the contents.
var currentUser = {
msg:data.msg,
id:id,
position:data.position,
}
socket.emit('move', currentUser);
Can I do something similar using this.state.roomname.push(currentUser) ?
Summary:
Learning to use Colyseus as a beginner.
Things I had considered when I started and trying out room handlers, specifically requestJoin(option) function.
https://codefalls.wordpress.com/2017/10/28/learning-colyseus-0-5-0/