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

0 Members and 1 Guest are viewing this topic.

Offline Oggy

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Help with hook.add
« on: July 12, 2013, 12: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
« Last Edit: July 12, 2013, 12:51:16 AM by Oggy »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • ****
  • Posts: 5520
  • Karma: 305
  • Project Lead
    • View Profile
Re: Help with hook.add
« Reply #1 on: July 14, 2013, 12: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, 12: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!