Channels and boolean toggling

Hello i m quite confused when using channels and toogling values. I had to pass thruth a changed node to deal with it.
This patch shows the right behaviour in an unexpected ( for me) manner.
Is there any better way ? thank you
toggle.vl (15.1 KB)

You don’t have to connect splicer to toggle, basically its just going to evaluate what’s inside of foreach, the connection itself does not have any value

You can see the channel is of type Unit, which means it has no specific value. A bang does not have a value per se, you’re just interested in when the event occurs. So then, it’s up to you to react to that event and do whatever you want with it, be it flipping a boolean, triggering an action, and so on.

In this screenshot, you can see that every time the button is clicked, we set the value of a bool channel to the inverse of what it was, recreating a toggle.

This is just one possible way of doing it though!

Hope this helps.

4 Likes

thank you @antokhio and @sebescudie ! its make more clear this question of channel being just an event, and not a value. yes its helpfull ! i didnt think to Two channels, one for event only, the other for value, as all channel examples with sliders or data are using only one channel to handle the value. It could be great to add @sebescudie example inside the channel help !

By the way, it would be great to mention that ForEach Region exists for channels.

works similarly, but is a bit easier to use in some contexts and works with multiple inputs

2 Likes

hello @yar, could you eventually provide an help patch to determine difference foreach and foreach and interrests ? Thank you !

For dealing with Channel(Unit) and getting a Boolean out of it I just use a HoldLatest node and use the On Data pin. It does the same, but is just a single node.

merci seltzdesign, i was using it in output of the foreach region (reactive)