Team Spartan Cookies & Milk Forums

Full Version: Problem with "input" hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When using
Code:
hook.add("input","a",a)
it seems that
Code:
a()
is not called when something is spawned already wired (think duping or updating/reloading) or when a wire is removed.

Is this intentional behaviour and is there a way around this? I'd like my server to sent a net message to the client whenever any wire anything is changed - and the "input" hook looks like the right one for this but doesn't seem to work.

I tried manually calling toClient() to send a net message to the client in my code - for when duped/updated - but for some odd reason the client recieved the correct new value which promptly changed to 0 - which is not correct.
The input hook is only called when things are written to an input on the chip, not when things are wired to it. Just check the values when you start the chip, I don't think there is any bug here.
Right. Checking the values when I start my chip causes a really weird problem, but that might just be my code. What about when something is unwired and returned to nil? It didn't trigger the input hook - but i'd like my screens to act as if unwired in that case.

Should I run a timer on them alongside the hook? I feel this might solve my problems but it doesn't sound very elegant.
The only time the hook is not triggered is when a duped or restarted, as the update happens before you can register your hook. You can compensate for that using
Code:
for _, v in pairs(wire.self():inputs()) do hook.run("input", v, wire.ports[v]) end
If you add a wire or remove it, the hook will get triggered.
Thanks!