Using other classes events

Anybody know of a way to access other public classes Events?

for instance i have lets say :

Class1 := class(creative_device):

  ExampleEvent : event() = event(){}

  OnBegin<override>()<suspends>:=void=

          ExampleEvent.Signal()

and then from another device/class i would like to figure out how await that events signal. Thought it would be something like this but having no luck

Class2 := class(creative_device):

  OnBegin<override>()<suspends>:=void=

           Class1.ExampleEvent.Await()

Do you mean like this…

@editable
HUDupdate : dynamic_text_device = dynamic_text_device{}
...
# in code...
 HUDupdate.someFunction()

…or am I misunderstanding?

I want to access the await function of the event from a different class so that when it’s signaled in my other class the function awaiting the signal can proceed.

If the function is ‘listenable’, you can generally do so with something like…

AnotherDevice.SomeListenableEvent.Subscribe(MyLocalEventHandler)
1 Like

will play around with that. Thank you

You still would need an instance of Class1 or someway to pass the ExampleEvent to Class2 to be able to call Await() on it.

Class2 := class(creative_device):
    Class1Instance : Class1 = Class1{}
    
    OnBegin<override>()<suspends>:void=
           Class1Instance.ExampleEvent.Await()
1 Like

Thank you for this one.

Adding @editable if you’re only ever using 1 instance of the class keeps it from creating an unnecessary extra instance too!

Much appreciated!

Can we already make our own listenable events? I thought this wasn’t available yet?

I’ve used them once or twice in the same class but never across multiple before.

The syntax is pretty simple

But you could do something simple like

EventName : event() = event(){}
var x : int = 0 


OnBegin<override>()<suspends>:void=
    CheckInt()
    branch:
        WaitingForEvent()

CheckInt():void=
    if(x > 2):
        random expression
        random expression 
        EventName.Signal()


WaitingForEvent()<suspends>:void=
    EventName.Await()
    #whatever you want to happen after the event is signaled

Or if you want to access it from another class do what PiEqualsThree Said and create an instance of the class you want to reference it from in the class you’re working in and then you can await the signal in other places too! :slight_smile: