Skip to content

Example of event readers? #76

Answered by minecrawler
drewww asked this question in Q&A
Apr 3, 2024 · 2 comments · 25 replies
Discussion options

You must be logged in to vote

Did you see the events example? Events usually should be run from systems and use the standard reader and writer.

In order to listen for added entities, you could write a system like this:

const EventListenerSystem = createSystem({
    entityAddedEvents: ReadEvents(SimECSAddEntityEvent),
}).withRunFunction(({entityAddedEvents}) => {
    let event;
    for (event of entityAddedEvents.iter()) {
        console.log('Entity Added!', event.entity.id);
    }
}).build();

If you really want to create your own reader, you'll want to also listen to the correct event name for added entities (SimECSAddEntityEvent). In your code, you also don't need to use line 2. eventBus.createReader() already regis…

Replies: 2 comments 25 replies

Comment options

You must be logged in to vote
16 replies
@minecrawler
Comment options

@drewww
Comment options

@minecrawler
Comment options

@drewww
Comment options

@minecrawler
Comment options

Answer selected by drewww
Comment options

You must be logged in to vote
9 replies
@drewww
Comment options

@minecrawler
Comment options

@drewww
Comment options

@drewww
Comment options

@minecrawler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants