Temporary Think hook?

Would I be able to go about making temporary use of a Think hook? Maybe this isn’t the solution I’m looking for; but my goal is to call a hook that runs in constant time, but only when I need it to, and not running as soon as the game initializes. I’d prefer to be able to stop the hook after it’s done, too. I’ve tried adding the hook when I need to call it, and logically removing it after it’s finished. Using hook.Add outside the hook and hook.Remove inside the hook, respectively. Though it seems extremely hacky, am I doing something wrong?

You could also use a boolean, which you can disable and re-enable whenever you want, as an alternative to hook.Remove.

Erm, do you mean putting logic at the start of the hook? If so and so then return end etc.


Yeah, that could work, but I just wouldn’t want to be running the hook at all when I’m not using it. Just for optimization concerns I guess.

[lua]timer.Create(“MyTimer”, 0, 0, function()
print(“Tick tock”)

– And control the timer like this.


timer.Remove(“MyTimer”) – When you’re done with it.[/lua]

You could try use a repeat-until or while loop.