View Single Post
07/20/22, 12:04 PM   #15
Masteroshi430
 
Masteroshi430's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2020
Posts: 185
Originally Posted by ZOS_DanBatson View Post
At best it could return whether or not it was a new registration or overwriting a registration, but that still wouldn't tell you if it was repeating and never going to fire, because it can only tell you about that one single attempt to register. There's no record of the number of times you overwrote or any previous attempts or anything like that. So it still comes down to the fact that you have to be cognizant of what you're writing. The main reason I didn't return that information is because I would never really have a legitimate reason to act on it in the moment. Whether it was new or an overwrite wouldn't actually change anything. The addon would still need to manually keep track of a count, and if you're going to do that, you can just do that with already by adding whenever you register and subtracting whenever you unregister or some such.

The other reason I didn't add the return is because if you call RegisterForUpdate from within some other update function, we actually delay the registration until the end of the frame, because we don't want to insert an update registration in the middle of us looping through all our existing registrations, potentially causing some kind of mismatch or desync of behavior. So technically, when that happens, you haven't actually overwritten anything yet. Most of the time this wouldn't manifest in a way anyone would even notice. But you could set up a situation where it would matter:

We register UpdateA and UpdateB. This frame, UpdateA starts running its function. As part of that function, it happens to meet a condition to overwrite the registration for UpdateB. Since we're in the middle of processing all the update functions, we queue that overwrite up and keep going. We then run UpdateB, which is still the old UpdateB. Then, after that's all done, we overwrite UpdateB, and next frame, when UpdateB runs, it'll be the new overwritten behavior.
Understood, thank you for the detailed answer.
  Reply With Quote