-
Notifications
You must be signed in to change notification settings - Fork 3
Create Custom Game Events
Jason Stallings edited this page Dec 6, 2022
·
11 revisions
Creating a new event emitter will automatically add the event to LuaEventManager.
import { EventEmitter } from '@asledgehammer/pipewrench-events'
// Define/Export a listener type
export type MusicTrackUpdateListener = (
track: string,
volume: number
) => void
// Create/Export the event
export const MusicTrackUpdateEvent = new EventEmitter<MusicTrackUpdateListener>('MusicTrackUpdate')
import { MusicTrackUpdateListener, MusicTrackUpdateEvent } from "./CustomEvents/OnCustomEvent"
// Create an event listener
const onMusicTrackUpdate: MusicTrackUpdateListener = (track, volume) => {
print(`Playing Track: ${track} (Volume: ${volume})`)
}
// Add event listener
MusicTrackUpdateEvent.addListener(onMusicTrackUpdate)
// Trigger the event
MusicTrackUpdateEvent.trigger("track01", 1.0)
// Remove event listener
MusicTrackUpdateEvent.removeListener(onMusicTrackUpdate)