-
Notifications
You must be signed in to change notification settings - Fork 18
Using Callbacks.md
Mirroar edited this page May 27, 2025
·
1 revision
Hivemind provides two special settings—onTick and onGlobalReset—that allow you to run your own code at key points in the bot's lifecycle. This lets you extend or customize the bot's behavior without modifying core files, making it easy to keep your changes compatible with upstream updates.
-
onTick: A function that runs at the start of every game tick, after the bot's memory and core systems are initialized but before most processes run. -
onGlobalReset: A function that runs once every time the bot is reloaded (e.g., after a global reset or code upload).
You can set these callbacks in your src/settings.local.ts file:
import {myOnTick, myOnGlobalReset} from './my-custom-callbacks';
const settings: Partial<SettingsObject> = {
onTick: myOnTick,
onGlobalReset: myOnGlobalReset,
};
export default settings;Create a file src/my-custom-callbacks.ts:
export function myOnTick() {
if (Game.time % 100 === 0) {
console.log('100 ticks have passed!');
}
}
export function myOnGlobalReset() {
console.log('Hivemind global reset!');
}Then import and use these in your settings as shown above.
- Keep your callback logic in separate files and only reference them in
settings.local.ts. - Avoid heavy logic in
onTickto prevent performance issues. Instead, use processes since they include built-in throttling and management. - Use
onGlobalResetfor one-time setup, such as initializing global variables or logging. - This approach ensures your custom code is not affected by upstream changes to the bot's main loop or process management.