Author Topic: Help with hook.add  (Read 392 times)

0 Members and 2 Guests are viewing this topic.

Offline Oggy

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Help with hook.add
« on: July 12, 2013, 01:23:11 AM »

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)

Code: [Select]
function ulx.XXX()
hook.add("TTTPrepareRound","callnextroundTG",ulx.XXX) --Is this possible?

Are my hooks rightly done?

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

« Last Edit: July 12, 2013, 01:51:16 AM by Oggy »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 5992
  • Karma: 357
  • Project Lead
    • View Profile
Re: Help with hook.add
« Reply #1 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.
Experiencing God's grace one day at a time.
My life on anime!

Offline Oggy

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Help with hook.add
« Reply #2 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!