---
description: Reacting to changes in the game.
---

# Events

Events are a highly efficient way of reacting to changes in the game engine, such as Npcs spawning and despawning, Skill level-ups, or Varps changing. RuneMate offers a variety of listeners that can be leveraged to this end.

## Listeners

The [**EventListener** ](https://runemate.gitlab.io/community/runemate-game-api/runemate-game-api/com/runemate/game/api/script/framework/listeners/package-summary.html)interfaces can be implemented in order to react to various events in-game. For example, we can use the [**EngineListener** ](https://runemate.gitlab.io/community/runemate-game-api/runemate-game-api/com/runemate/game/api/script/framework/listeners/EngineListener.html)to run some code every tick:

{% code title="MyEngineListener.java" %}
```java
public class MyEngineListener implements EngineListener {

    private int tick;

    @Override
    public void onEngineEvent(EngineEvent event) {
        if (event.getType() == EngineEvent.Type.SERVER_TICK) {
            tick++;
        }
    }

}
```
{% endcode %}

## Event Dispatcher

The **EventDispatcher** is the core of the event framework, and all listeners must be registered with it. An instance of the EventDispatcher is provided by your bot instance:

{% code title="MyBot.java" %}
```java
public class MyBot extends LoopingBot {

    private MyEngineListener listener;
    
    @Override
    public void onStart(String... args) {
        getEventDispatcher().addListener(listener);
    }
}
```
{% endcode %}
