BEAKSBY 11 Posted August 3, 2014 (edited) HI All, I'm trying to determine if some minor bugs occuring in my scripts are caused by removing the event handlers ? Why do you have to remove the EV?Note that the BIKI page says that any EV with a higher index than the EV you are removing needs to decremented. It seems like it could cause a lot of bugs if you try to remove it and keep track of any index since many addons and likely A3 itself adds killed EV's. cuel replied from this http://forums.bistudio.com/showthread.php?179260-Do-my-two-addEventHandlers-“Killedâ€-need-a-different-Number-(index)...so does anyone out there delete their EHs, and if so, do you then decrement any other EH associated with the object? What is the benefit of removing the EH? How do I display either some sort of unique ID associated with the object or even just the incremental index number of the added event handlers? from Indices start at 0 for each unit and increment with each added event handler. http://forums.bistudio.com/showthread.php?181471-What-is-the-benefit-of-removingaddEventHandler Edited August 3, 2014 by BEAKSBY Share this post Link to post Share on other sites
norybiak 10 Posted August 3, 2014 Hi BEAKSBY, Each object (players, vehicles...) that has an EH added to them will start at index 0. Each type of EH will also start at index 0. Only when an EH of the same type is added to the same object are you then obligated to keep track of the indices if you intend to remove an EH of that type later on. A good way to keep track of EHs is with the use of an array, though this is in the case of having many of the same type EHs. In the event that you need to delete an EH, any EH that is created after, or with a higher index, must be decremented. Think of it as a line of people waiting to buy a new video game. If a person in that line decides to leave, everyone behind him/her moves up, filling in the gaps. In the case of index handlers, since the variables or array (which ever is used) that hold the indices don't know when an EH is removed, changing the index handler for the EHs after the one that is removed must be done manually. For the most part, an EH of the same type is never added twice to the same object, thus there is no reason to keep track of it since index 0 is always the first EH. If you intend to use the EH throughout the entire mission, then there is no reason to remove it. If not, then removing it will prevent unnecessary code from running. From your previous thread: http://forums.bistudio.com/showthread.php?179260-Do-my-two-addEventHandlers-%E2%80%9CKilled%E2%80%9D-need-a-different-Number-(index), your initServer.sqf file has two "killed" EH, one that is added to every vehicle and the other that is added to every player. In this case, since each object is different, you do not have to keep track of the indices and the EHs are not conflicting with each other. From what I understand in the code, once the EH is created you assign the _handle variable with _unit getVariable [ "DNA_EH_Killed_Money", -1 ]; . You then proceed to remove the EH using _unit removeEventHandler [ "Killed", _handle ]; . This doesn't make sense as _handle is assigned -1, and -1 is not a proper index for any EH. My suggestions in your case is to: - not delete the EH as they don't appear to conflict with each other since every object gets its own EH - double check your code as I see a few errors (check your variables, _unitType as a starter) Best, NorybiaK Share this post Link to post Share on other sites
fn_Quiksilver 1636 Posted August 3, 2014 An event handler is a loop (a tight one too) and has a performance cost, that is a reason to remove when not required and only add when required. Share this post Link to post Share on other sites
Larrow 2821 Posted August 3, 2014 Ignore the wiki about decrementing EH ID's, although i believe this was the case at some point it is no longer true, thankfully, and made EH's painful to use and ID's worthless. For reference Share this post Link to post Share on other sites
nimrod_z 8 Posted August 3, 2014 if you ever use damagehandler EH you should remove them on units death as they will continue to fire even if corpse gets damaged. Share this post Link to post Share on other sites
norybiak 10 Posted August 3, 2014 Ignore the wiki about decrementing EH ID's, although i believe this was the case at some point it is no longer true, thankfully, and made EH's painful to use and ID's worthless.For reference I havent tested this out personally (and I will soon), but if it is true then that does indeed save a bit of work for those who use more than one same type EH. However, your reference doesnt prove that this is the case. I mean no disrespect, and I trust your actual testing was more in depth, but you must show concrete proof that this is the case (I am curious too). Share this post Link to post Share on other sites
Larrow 2821 Posted August 3, 2014 Thats why i post for reference, there is noway of showing proof other than trying for yourself. evhandle0 = this addEventHandler ["GetIn", {player sidechat "EH 0";}]; evhandle1 = this addEventHandler ["GetIn", {player sidechat "EH 1";}]; evhandle2 = this addEventHandler ["GetIn", {player sidechat "EH 2";}]; To your vehicle, on getting in the vehicle you will see three sidechats. The variables evhandle0 to 2 hold the index of each added Eventhandle so 0 to 2. If you were to remove one of the events via removeEventHandler ["GetIn",1] same as saying removeEventHandler ["GetIn",evhandle1] on entering a vehicle you would now see sidechat for 0,2. Removing the same index again will make no difference as the indexs do not readjust, EH 2 is still at index 2. The proof is right there for you to test yourself Removing the same index again will make no difference as the indexs do not readjust, EH 2 is still at index 2.Spam either myVeh removeEventHandler ["GetIn", 1] or myVeh removeEventHandler ["GetIn", evHandle1] as much as you like your still get the same chat messages on entering the vehicle because the EH indexs have not moved to fill in the empty index of the removed EH, but remove myVeh removeEventHandler ["GetIn", 2] or myVeh removeEventHandler ["GetIn", evHandle2] and the last message will disappear proving that eventHandlers do not decrement their handle index's. Share this post Link to post Share on other sites
BEAKSBY 11 Posted August 3, 2014 Do "killed" EH get removed when the object they are associated with is killed, then removed from a clean up script (using deleteVehicle)? Do you think I will be able to measure the performance cost by simply observing the framerate (with Fraps)? My game creates new "killed" EHs, every time a player purchases a vehicle and one is spawned. There can be up to 50 vehicles created in the game and therefor 50 EHs! Share this post Link to post Share on other sites
norybiak 10 Posted August 4, 2014 (edited) EH are not removed when an object is killed, however, when the object is removed the EH is then also removed. It would be hard to measure the performance of EHs using just Fraps, or any other program that shows your frame rate in game, as there are a lot of variables involved that could easy contribute to FPS fluctuation. EHs are executed locally (with the exception of MP EHs), meaning the code runs on the machine in which the EH was added to, thus not every EH added contributes to server performance costs. I am not sure what the behavior is regarding locality of EHs that are attached to vehicles. If anyone can clarify this, then that would be fantastic. I believe you shouldn't worry about the performance of EHs unless you physically notice any problems. EHs are fast and efficient, so having 50 EHs handled by the server (if that's the case) isn't going to cost much, but you should make sure to clean up anything that isn't necessary. Edited August 4, 2014 by norybiak Share this post Link to post Share on other sites