Custom events (Idea)

From 8x9craft
Jump to: navigation, search

Let users define custom events and broadcast them.

Examples

// crab.on(eventName: String, callback: (sender: Crab, data: any) => void): void
crab.on('event-name', (sender, data) => {
    crab.say(sender.getName() + ' sent a message!');
    if (data.bool) {
        for (let i = 0; i < data.number; ++i) {
            crab.run(data.string);
        }
    }
});

// crab.broadcast(eventName: String, data: any, sendToSameOwnerCrabsOnly: boolean, maxDistance: Number): void
crab.broadcast('event-name', { number: 4, bool: true, string: "Tak" });

See also