Skip to content
LabRicecat edited this page Nov 25, 2022 · 3 revisions

Events are stored as a list of functions with a certain visibility.

To define an event you use the event command:

event <visibility> name([parameters])

There are 4 visibility:

  • public
  • private
  • occur_only
  • listen_only

An event that is public can be accessed by any file. A private one only by the file it was defined in. occur_only and listen_only are self explanatory, but they only restrict the use if their outside of the file they were defined in!

Listen to an event

To "listen" to event mean to append a listener function that gets added to the list of the event.

listen <event>(<parameters>) {
  ...
}

Letting an event occur

To let an event occur means to execute all listeners with some given arguments in the order they got appended to the event.

occur <event>(<arguments>)

Example

event public greet_all()
event public calc(num :: Number)

listen calc(num) {
	print (num + 10)
}

listen greet_all() {
	print "Hello Bob!"
}

listen greet_all() {
	print "Nice to see you liz!"
}

listen calc(num) {
	print (num * num)
}

occur greet_all()
occur calc(12)

This will output:

Hello Bob!
Nice to see you liz!
22
144

>>> Next Article

Clone this wiki locally