Reversible patterns

Thank you both @semiquaver and @jamshark70 for the detailed explanations. I understand a lot better now what is going on. I’ve successfully implemented your concepts in my little silly task (a touch sensor pauses and releases the task, an accelerometer determines wether the task has to be “rewinded” or “sped up” faster, and releasing the touch sensor brings the sequence back to normal speed and direction).

I never thought of this but it makes a lot of sense. I don’t know if it’s a pertinent example, but I think this is explanatory as well of why Eli creates two variable (~buttonVal and ~lastButtonVal) in this example, while creating a system to check for identity values coming from an external button, and only printing/outputting the “new” values (so to filter out repetitions): https://www.youtube.com/watch?v=5A4DhtuPjdc&t=6443s . Am I right?

Mine was totally an assumption indeed, the point for me was that it’s rather confusing when to use a Tdef, when to use a task, when to use a Pdef and when to use pretty much any other kind of pattern. For instance: I am not sure why you turned the Pscratch into a stream outside the looped part in the Tdef, but I’ve figured that I could upscale this example to make it fit in my current example and I avoided asking a load of other questions. I think it’s gonna be hard to get used to these things but some of my major doubts have already been clarified by your answers. I appreciate a lot the time you’ve dedicated into it :slight_smile:

OK, think about this… what if it was turned into a stream inside the loop?

Then every loop iteration would reset the stream to the beginning – certainly not what you want. And how could you prevent that? Well, if it’s inside the loop, then by definition you can’t prevent it. So the solution is: don’t put it in the loop.

The key is that the stream’s state needs to persist from one iteration to the next. This generally means that the persistent “thing” should be defined outside of the context where it’s used – here, outside of the loop; in Eli’s tutorial, state variables defined outside of the responder function.

hjh

2 Likes

great, i’m starting to grasp this better. thanks for the patience and the thorough explanations!!! you are really good at making things understandable lol