Device event spamming custom events when subscribed to a function

Here in this snippet I have a prop manipulator event “DamagedEvent” subscribed to this other function that simply prints “Gun Fired!” as a test:


sentrygun := class(creative_device):

@editable var Detector : prop_manipulator_device = prop_manipulator_device{}

OnBegin<override>()<suspends>:void=
    loop:
        Sleep(0.1)
        Detector.DamagedEvent.Subscribe(GunFired)

GunFired(Agent : agent):void=
    Print("Gun Fired!")

The only issue with this code is when I damage a prop with this prop manipulator attached, it spams the log with “Gun Fired!” many, many times instead of just once, which is what I thought it would do. Can anyone let me know if I’m doing something wrong? Thanks.

Maybe a little late with answering but I think it’s because you subscribe to the event inside a loop that you get the printed message lots of times.
Basically every 0.1 seconds you subscribe again to the same event and when the event triggers, all those subscriptions fire and you get those messages.

Try subscribing without the loop and see if that fixes your problem.

2 Likes

Yeah I was new to verse then but I understand my mistake now

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.