Z4Zy Posted October 26, 2018 Share Posted October 26, 2018 Hello ! when there's an event handler like below, function vehicleEnter(vehicle,seat) if seat == 0 then outputChatBox("You have entered a "..getVehicleName(vehicle),source,255,255,0) end end addEventHandler("onPlayerVehicleEnter",root,vehicleEnter) we can remove it from one line code like below, removeEventHandler("onPlayerVehicleEnter",root,vehicleEnter) So that's all. BUT !, when there's an event handler like below, addEventHandler("onPlayerVehicleEnter",root, function (vehicle,seat) if seat == 0 then outputChatBox("You have entered a "..getVehicleName(vehicle),source,255,255,0) end end ) How to remove that event handler ? are there any way ? Link to comment
MIKI785 Posted October 26, 2018 Share Posted October 26, 2018 You can't remove that. It's an anonymous function, so you don't have the pointer to it (its name). You can't reference anonymous functions, therefore you can't reference it in removeEventHandler. 1 Link to comment
Z4Zy Posted October 26, 2018 Author Share Posted October 26, 2018 4 minutes ago, MIKI785 said: You can't remove that. It's an anonymous function, so you don't have the pointer to it (its name). You can't reference anonymous functions, therefore you can't reference it in removeEventHandler. so, aren't there any why to remove that type of event handlers ? Link to comment
LyricalMM Posted October 26, 2018 Share Posted October 26, 2018 11 minutes ago, DeadthStrock said: so, aren't there any why to remove that type of event handlers ? nope, just separate lines Link to comment
Moderators IIYAMA Posted October 26, 2018 Moderators Share Posted October 26, 2018 (edited) local handlers = {} do local _addEventHandler = addEventHandler function addEventHandler (...) local result = _addEventHandler(...) if result then handlers[#handlers + 1] = {...} return result end end end Wrap it. Just make sure to clean the table once in while. Or get the attached function with this function, if you know the event and the element. https://wiki.multitheftauto.com/wiki/GetEventHandlers ____ Yet, you can better name your a dogs. If it is called fluffy, then you only have to call 'fluffy, your dinner is ready' and it will surely come back to you. If you didn't name him, then you have call out like this 'fluffy-dinner is ready'. After that I am not sure how many streetdogs will come back to you. (Not even sure if fluffy would survive that...) Edited October 26, 2018 by IIYAMA Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now