Creating a room from another room?
-
I have a flow that when a client enters the game, I use
getAllAvailableRooms
to get all game lobbies a client can join, or allow him to create a new one (See the PR I sent tocolyseus
).After they join a game lobby, they basically join a GameLobby room, which waits until all clients are ready and the owner presses
Start
and the game should then start.My idea is that I should be able to create a room from inside the
onMessage
function,
which would in turn give me the newly createdroomId
, which I can broadcast to my players with astart_game
action.But unfortunately, a room cannot access the matchmaker...
Given that - how would you go and make something like that?
Btw, this is the repo for code example and references.
-
Found sort of a solution - use
RegisteredHandler
'screate
event to subscribe to the room's event.
The changes can be found here.I wanna make an important note here:
Creating an
async main
method inindex.ts
andawait
inggameServer.register
was crucial.