event

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package event implements WolfMUD's asynchronous scripting mechanism.

Index

Constants

This section is empty.

Variables

View Source
var FindName func(has.Thing) has.Name

FindName is an indirect reference to the attr.FindName function. The attr package cannot be imported directly as it causes a cyclic dependency. However the attr package can import the event package to initialise this variable which we can then use. See init function in attr/name.go for initialization.

View Source
var Script func(t has.Thing, input string) string

Script is an indirect reference to the cmd.Script function. The cmd package cannot be imported directly as it causes a cyclic dependency. However the cmd package can import the event package to initialise this variable which we can then use. See init function in cmd/state.go for initialization.

Functions

This section is empty.

Types

type Cancel

type Cancel chan<- struct{}

Cancel is a send only channel that can be used to cancel a queued event. When an event is queued via Queue a Cancel channel will be returned. The Cancel channel should be closed to cancel the pending event that was queued.

func Queue

func Queue(thing has.Thing, input string, delay, jitter time.Duration) (Cancel, time.Time)

Queue schedules a scripted event to happen after the given delay. Queue returns a channel to cancel the event and the time of when the event is expected to fire.

The firing time is only the expected time and not guaranteed to be 100% accurate due to system load, scheduling and processing delays. Typically delays are expected to be < 500µs (0.0005s). Delays can be monitored by setting Debug.Events to true in the configuration file, in which case the delivered messages will contain the amount the event was delayed by, for example: "Event delivered (delayed 127.596µs)"

The passed Thing is expected to be the 'actor' for the scripted event.

The input string can use any normal player command and in addition can use the scripting only commands starting with the '$' symbol.

The event can be cancelled by closing the returned Cancel channel.

The delay is the period after which the command will be run. The jitter is a random amount that can be added to the delay. So the actual delay for an event will be between delay and delay+jitter. For a totally random event delay can be 0s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL