Ulysses

General => Developers Corner => Topic started by: Oggy on July 12, 2013, 01:23:11 AM

Title: Help with hook.add
Post by: Oggy on July 12, 2013, 01:23:11 AM
Hello!

I'm kinda new to lua, have experience from VB since before.
I can't get around to understand how hooks work.

Is it possible to use hooks in an function? Or do they need to be outside an function?
If it is, is it also possible to recall that function with a hook in the function? (to make it automatic, will use hook.remove in another function)

Example;
Code: [Select]
function ulx.XXX()
hook.add("TTTBeginRound","startmodeTG",startatgmode)
hook.add("TTTEndRound","resetinvTG",synligatrait)
hook.add("TTTPrepareRound","callnextroundTG",ulx.XXX) --Is this possible?
end

Are my hooks rightly done?

Edit:
Am I on the right track here thinking that hooks disappear after use? Or are they still active to the next time?

Thanks!
/Oggy
Title: Re: Help with hook.add
Post by: Megiddo on July 14, 2013, 01:42:11 PM
You're thinking too object-oriented here. Lua is a mostly procedural language. Hooks are added when you call hook.Add. If you're calling hook.Add inside a function, they won't be added until you call that function. Hooks stay permanently unless removed.
Title: Re: Help with hook.add
Post by: Oggy on July 15, 2013, 01:28:24 AM
Yeah I figured this out.
I was using "hook.add", and thought I was doing something terrible wrong, but then I realised it should be "hook.Add", and it solved itself.

Thanks for the reply though!