Getting Started
Installation
To start using Evently in your project, you first need to install the package via npm:
npm install @terradreamgames/eventlyConfiguration
Since this package is not under the @rbxts namespace, you must configure your project to recognize it.
Update tsconfig.json
Add the following to your tsconfig.json:
{
"typeRoots": ["node_modules/@rbxts", "node_modules/@terradreamgames"]
}Update default.project.json
Add the following to your default.project.json:
{
"rbxts_include": {
"$path": "include",
"node_modules": {
"$className": "Folder",
"@rbxts": {
"$path": "node_modules/@rbxts"
},
"@terradreamgames": {
"$path": "node_modules/@terradreamgames"
}
}
}
}Defining Events
Use the EventDefinitions function to create an event system with strongly typed event definitions. Define your event names and their corresponding data types in a single object.
Example:
import EventDefinitions from "@terradreamgames/evently";
interface Test {
roblox: string;
game: number;
}
const events = EventDefinitions<{
foo: Test;
}>();Registering Handlers
Use the on method to register handlers for specific events.
events.on("foo", (data) => {
print(`Game: ${data.game}, Roblox: ${data.roblox}`);
});Triggering Events
To fire an event and pass data to the handlers, use the trigger method:
events.trigger("foo", {
roblox: "roblox",
game: 123,
});