Ulysses
General => Developers Corner => Topic started by: Buzzkill on December 19, 2014, 11:01:51 AM
-
Hey all. Trying to understand some results I'm seeing. I've got two hooks for EntityTakeDamage, one as part of a gibmod addon and another as part of a lua script I'm introducing in /lua/autorun. The autorun hook is being added with a priority of -10. The addon hook is being added without a priority (default of 0).
If I understand correctly, when ULib initializes it queries the current list of hooks and rebuilds them (ulib\shared\hook.lua). I would expect that the EntityTakeDamage hook from autorun (priority -10) would execute before the addon version. However, debug statements are showing me that the addon version is running first.
Is the Ulib prioritization of hooks only for hooks within ULX, or should it apply to legacy hooks as well? Is there something that might prevent the prioritization/sorting of hooks as expected?
Also, any tricks to debugging within hook.lua? It seems that various efforts at printing debug info yield errors.
Thanks!
Mike
-
Buzzkill, I can't help with the debugging like your asking (Megiddo/Stickly are the experts for our code there), but, it's likely your hook.Adds are running before ULib is initialized.
(You might find ULib's debugFunctionCall (http://ulyssesmod.net/docs/files/lua/ulib/shared/messages-lua.html#debugFunctionCall)
Looks like our hook code doesn't verify if a hook already has a priority when it's adding stuff from the 'old' list.
So, if you set that extra parameter before ULib adds the hooks, it sets it to 0 anyway.
I could have sworn we had a hook or function that got called when ULib loaded and was "ready" for other dependencies, so you could do something like hook.Add("ThisHookCalledWhenULibInitialized", your function/code to add more hooks, blah) but I can't find it.
I know we use a variable to test for some stuff "if ULib then ...", but that would be inconvenient in a timer/etc just to start your code/adds.
-
Bingo! That makes perfect sense, and by moving my scripts into ulib/modules I was able to insure that they didn't hook until after Ulib overrode hook management. Problem solved. Many thanks!
-
Welcome, and...
BINGO #2. I knew we had something. Not well documented though.
Not very helpful if you're not using ULX and only wanting our ULib library though (hey, uncommon, but could happen).
hook.Add ( ulx.HOOK_ULXDONELOADING, blah, blah )
Can search our repo for that if examples needed. I found it a few times to ensure we had configs loaded 'after' the rest of ulx had loaded, XGUI post init, echo colors, etc.