Concurrency, custom event never tracked?

When using a custom event to check when a player “Gets back on a vehicle” the event GotBackOnVehicleEvent(Slot).Signal() never wins in my race event!

What am I doing wrong? Snippet:

    GotBackOnVehicleEvent<public>(Slot:int) : event() = event(){}
    ExitedVehicle(Agent:agent, Slot:int):void=
        Print("Player exited Vehicle! Slot: {Slot}")
        spawn { CheckRespawnVehicle(Agent, Slot) }

    CheckRespawnVehicle(Agent:agent, Slot:int)<suspends>:void=
        race:
            block:
                GotBackOnVehicleEvent(Slot).Await()  
                Print("Player got back on vehicle! Slot: {Slot}")              
            block:
                Sleep(EmptyVehicleRespawnTime)
                Print("Player didnt get back on vehicle in time!")
                if. Vehicle := DirtBikes[Slot] then Vehicle.RespawnVehicle()

    EnteredVehicle(Agent:agent, Slot:int):void=
        Print("Player entered vehicle! Slot: {Slot}")
        GotBackOnVehicleEvent(Slot).Signal()

All Print events happen except for:

Print("Player got back on vehicle! Slot: {Slot}")

GotBackOnVehicleEvent is a function and thus returns a new event() object every time - you should use an array or map instead to ensure the same object is being used

1 Like

Hey @Ep8Script, thanks for the reply.

Can you explain this further? I’ve successfully used events before, for example if I used

GotBackOnVehicleEvent<public>() : event() = event(){}

and

GotBackOnVehicleEvent().Signal()

These would work fine - how exactly does adding Slot:int change it’s purpose and in what scenario would I use this if not in my case?

Edit: I solved my particular case by using a class that handles events, however still questioning how changing the payload broke things.

Each time you run GetBackOnVehicleEvent here, a new event object is created - therefore calling GetBackOnVehicleEvent().Signal() will signal a different event to what GetBackOnVehicleEvent().Await() is awaiting - to have them be the same event object, you’d need to store the event object somewhere as a constant or variable

Are you sure you had this working previously? It shouldn’t be possible

Interesting, I’ve used it several times this way! Pretty sure there’s also official docs using it in this way.

Can you double check? I’m very curious because it shouldn’t be possible lol, but happy to be wrong about it!

Just checked another project and its set up like above. Looking for doc examples!

Are you able to definitely verify it works or share code that does? I’m confused :sweat_smile: