Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom events #1093

Open
gabrielecastellano opened this issue Sep 8, 2022 · 2 comments
Open

Custom events #1093

gabrielecastellano opened this issue Sep 8, 2022 · 2 comments
Labels

Comments

@gabrielecastellano
Copy link

Thanks for this amazing framework!

I am encountering a possible limitations in triggering some actions whenever something happens. Indeed, the available Events API is only for predefined events and is only related to the ctx object.

To my understanding, it is not possible to create a custom event, and trigger / handle it server side from multiple areas of the code. For instance, I could define an event "CardPlayed" that is notified within a move (every time a player plays a card). Then, if there are one or more handler registered for that event, they will be executed. Otherwise nothing would happen.

Am I missing something?

@vdfdev vdfdev added the question label Oct 7, 2022
@rosie-i
Copy link

rosie-i commented Apr 2, 2023

Hi, did you find any solution to this issue? I'm having a similar problem and feel like I'm missing something around how to implement custom events in moves. Thanks.

@gabrielecastellano
Copy link
Author

Hello Rosie!
I don't know if there is a better way of doing so provided by the boardgameio framework, btw, I solved the problem by initializing an EventEmitter at the beginning of every server-side stuff in my code (e.g., at the beginning of every move, at the beginning of every onBegin, onEnd, etc.). I create the emitter, subscribe all the possible events listeners to it, and then execute the rest of the move. If within the move there is some piece of code emitting an event (using the created EventEmitter), of course, they would trigger the proper listeners.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants