Button/Trigger to set the state to zero Created 2 years ago2022-11-03 20:30:15 UTC by Kaner Kaner

Created 2 years ago2022-11-03 20:30:15 UTC by Kaner Kaner

Posted 2 years ago2022-11-03 20:30:15 UTC Post #347042
Hello everyone,

Is there anyway to set the state of an entity to 0 (zero) instead of toggle it (0 to 1 and 1 to 0) ?

Thanks!
Posted 2 years ago2022-11-04 01:07:16 UTC Post #347043
You can use a trigger_relay to send an off (or on) signal to other entities. However, not all entity types check the kind of signal that they receive, so some will get toggled regardless.

In some cases it's useful to kill an entity instead (if you don't need it afterwards). In other cases you may need a mechanism that keeps track of an entity's state. A while ago I experimented with using a button_target for that - it has the useful property of only triggering its target when its state changes. So if you send an off signal to a button_target that's already off, it won't trigger its target.
Posted 1 year ago2022-11-27 18:09:47 UTC Post #347133
Thank You Captain P,
I have been trying with no success just using trigger_relay, can you share your test map with also button_target or give me some draw/schema?
Posted 1 year ago2022-12-10 22:23:24 UTC Post #347159
I don't know if I still have that test map, but here's how it worked if I remember correctly.

Normally, you trigger entities directly by using their name as the target of a trigger or button or something:
trigger --(toggle)--> target entity

To turn an entity off, you trigger a trigger_relay instead, and use that trigger_relay to send an 'off' signal (trigger state) to the final target:
trigger --(toggle)--> trigger_relay ('off') --(off)--> target entity

Not all entities can handle 'off' signals however - some entities are always toggled, regardless of what signal they receive. For those, you could put a button_target in-between. If you send an 'off' signal to a button_target that is on, then it will trigger its target and turn itself off. If you send an 'off' signal to it while it's already off, then it will not trigger its target:
trigger --(toggle)--> trigger_relay ('off') --(off)--> button_target --(toggle, if button_target changed state)--> target entity

So the idea is to use a button_target to 'remember' the state of the final target. It's not perfect: you have to make sure that the button_target always has the same state as the final target. That can be tricky, for example with func_doors, which ignore triggers while they're still moving (for example, your button_target receives an off signal, toggles the func_door to close it, and turns itself off, but the func_door was still moving to its open position, so it ignored the toggle, and thus ends up being open, not closed), so in some cases even more elaborate setups may be needed.

Either way, I suppose this technique could be useful in some cases.
You must be logged in to post a response.