I have game logic where some things initiate when a timer completes. It all works fine, unless someone navigates away. When they break the loop, the timer and action still occur, and it pulls them out of whatever new screen they’re on and deposits them back in the original loop. How do I turn off the delay event flow when they navigate somewhere else?
The expected functionality is that when you navigate away from a page, any loops inited from that page should cease to function, but it’s currently not working like that.
What you could do is add a page variable (might have to be an app variable) for loopShouldContinue, and then an If condition node after the Delay node in your loop that goes to an empty output if the variable is false.
Then, on your page logic canvas, add a Receive event node and change its type to Page will unmount – this event triggers when the user navigates away from the page. Then, just attach a Set page variable node to set your loopShouldContinue to false, and the loop will break next time the If condition is reached.
Just dug this topic up after screaming silently in frustration for a while, unable to explain why my second page was going haywire.
The way it works currently is very unintuitive (and, it appears, unintentional). My previous app was basically single-page, but now that I’m getting into multi-page apps, it’s astonishing to me that this isn’t a bigger deal / doesn’t come up more often! (And doesn’t even have a bug report filed for it that I can find! Fixing that now.)
In my case I have an extremely fast (60ms) loop on my first page to keep latency as low as possible in a multi-player use case, so it’s a bit frustrating that I have to add an “if” check in there every cycle to determine whether it should be terminating or not.
That actually is a sensible solution that @Harri_Sarsa described (which i often use If.conditions to exit out of loops myself). I disagree that loops should automatically exit when navigating to another page because there are use cases ehere a loop running “globally” is desired.
We definitely want to include better native support for loops; I agree it’s not intuitive ATM.
If you want to ensure a loop stays active, it should be always kept on the Global Canvas – though pages currently keep executing logic after being navigated away from on mobile, the Global Canvas is the right place for loops that do not have to deal with the currently active page.
I agree that globally running loops are desirable! But I think it’s very counterintuitive to assume that a loop begun in a specific context (in this case, within a page) will continue to function outside of that context. You should have to designate a loop as global, not the other way around.
This also becomes a technical issue with certain Event triggers like “App variable X changed,” which cannot be preceded with a loop. If I navigate away from Page A, my “App variable X changed” listener from that page still keeps running even though I don’t want it to. And sure, I can make the next step an IF to check, “Am I currently on this page?” But by the time I get to Page Z, now I have… 26 listeners for the same app variable all running in the background? Plus, what happens if I want to go back to that page? (This is not a rhetorical question – I actually don’t know Like, do I now have two listeners running on this page, or one?)
I see what you mean now and agree that Page loops - as well as all code within the context of a Page - should terminate when exiting the Page. This is a problem I have noticed and dealt with before with Data variables default 5 second default initialization loops.