For those who also want to use classic events
Example Usage:
using { /Fortnite.com/Devices }
a := class:
ValueChangedEvent<public> : int_event = int_event{}
SetValue<public>(Value : int) : void =
ValueChangedEvent.Invoke(Value)
main := class(creative_device):
A<private> : a = a{}
OnBegin<override>() : void =
A.ValueChangedEvent.Subscribe(OnValueChanged)
A.SetValue(10)
A.SetValue(20)
OnValueChanged<private>(Value : int) : void =
Print("Value is changed: {Value}")
By placing these pieces of code in a separate file, you can enjoy all the conveniences of regular events:
If you have no arguments:
no_args_event_listener := type{_():void}
no_args_event := class:
var Listeners<private> : []no_args_event_listener = array{}
Subscribe<public>(Listener : no_args_event_listener) : void =
set Listeners += array{Listener}
Invoke<public>() : void =
for (Listener : Listeners):
Listener()
With int argument:
int_event_listener := type{_(:int):void}
int_event := class:
var Listeners<private> : []int_event_listener = array{}
Subscribe<public>(Listener : int_event_listener) : void =
set Listeners += array{Listener}
Invoke<public>(Value : int) : void =
for (Listener : Listeners):
Listener(Value)
With agent argument:
agent_event_listener := type{_(:agent):void}
agent_event := class:
var Listeners<private> : []agent_event_listener = array{}
Subscribe<public>(Listener : agent_event_listener) : void =
set Listeners += array{Listener}
Invoke<public>(Value : agent) : void =
for (Listener : Listeners):
Listener(Value)
There is also a universal option, but it does not yet work in our verse version:
“Mutable members in parametric classes are not yet implemented.”
endo_event(t:type) := class:
var Listeners<private> : []type{_(T : t) : void} = array{}
Subscribe<public>(Listener : type{_(T : t) : void}) : void=
set Listeners += array{Listener}
Invoke<public>(T : t) : void=
for (Listener : Listeners):
Listener(T)