colyseus/command

Feature Request: Possibility to have a return value in the execute function

Wenish opened this issue · 1 comments

Imagine following scenario:
Creating a Unit Entity
After that create a Player Entity which can control this unit

onJoin(client: Client, options: any, auth: any) {
    const unit = this.dispatcher.dispatch(new UnitAddCommand(),{})
    this.dispatcher.dispatch(new PlayerAddCommand(), {
        sessionId: client.sessionId,
        unitId: unit.id
    });
}

So i would like to create a command like this:

export class UnitAddCommand extends Command<RoomState, UnitAddPayload> {
   execute(payload: UnitAddPayload): UnitState {
       const unit = new UnitState()
       this.state.units.set(unit.id, unit)
       return unit
   }
}

This would be a really nice feature IMO.

Feel free to ask questions.

I want to do the same thing. Any updates or workarounds for this to work?