Describe the bug
/srun triggerEvent("asdasdasdas", me)
Unlike non-existant events with triggerClientEvent or triggerServerEvent, triggerEvent will not give out an error if the event which we're trying to trigger doesn't exist.
To reproduce
/srun triggerEvent("asdasdasdas", me)
Expected behaviour
It should give an error that such custom event doesn't exist.
Screenshots
Version
Additional context
This can lead to an issue where you have forgotten to register your custom event, and you use addEventHandler, and you wonder why your function doesn't execute even though triggerEvent was called... but little did you know... you forgot to use addEvent. If only debugscript had told you that you're trying to trigger a non-existant custom event...
Did you try checking the return value ? According to the Wiki it should return nil if the event doesn't exist. Not sure if the runcode resource checks it properly
Returns nil if the arguments are invalid or the event could not be found.
Yes, it returns nil, but that's not the issue here. The issue is that debugscript doesn't say that there was a trigger for non-existant event. If you try to trigger non-existant events with triggerClientEvent or triggerServerEvent, it gives an error that event doesn't exist, but with triggerEvent it doesn't say anything in debugscript.
You should've used the Feature request template for the issue, because there is no bug.
Some resources trigger events to notify other resources about things. e.g. race uses onClientMapStarting, onClientPlayerOutOfTime and others to help race add-on resources.
So this feature would cause unnecessary log spam if the listening resources are not running.
In that case I think we should reject this proposal
Maybe we could add a setting on the mtaserver.conf about this type of warnings?
Maybe we could add a setting on the mtaserver.conf about this type of warnings?
This would raise warnings in default resources, which is undesirable.
We could extend getEventHandlers to return all events (not just ones bound to a specific element) and handlers (this list of functions could be empty). That way you could monkey-patch addEventHandler to add this check for yourself.
Alternatively we could add an extra param to triggerEvent that ensures that the event exists, but I don't think the new API for this would be elegant.
Triggering events which don't exist is the responsibility of the scripter. I think this is a non-issue and should be closed.
you forgot to use addEvent. If only debugscript had told you that you're trying to trigger a non-existant custom event...
I think not, usually it tells you that the event triggered has not been added (client/server)-side, with enough experience that's usually because you forgot to addEvent or the event doesn't exist because of a typo or something.
No response from the author in a month so I'm closing this.
Most helpful comment
In that case I think we should reject this proposal