When an async Action is in a loop, the loop will continue to move forward. All the Async method are respected, which mean each of them will run the correct Actions with the correct object set etc.
But the sequence is broken.
Code for repro :
What will happen there : the system will go through the entire loop, then 2s later all the V will show at once.
- The loop starts
- The system wait 2s
- Update of the text
- Incremental step of the loop
- Then next loop…
From the event you have here, this is expected behavior. (Edit: as far as I can tell)
Repeats do not care about other portions of repeats, they just do their actions X times within a single frame.
Meaning within 1 frame, you’re starting 4 waits at once (each likely 0.001ms between each other). The first wait will not impact the 4th wait.
To do what you’re thinking of, you’d probably be better off not using a wait nor a repeat event, but a timer and some kind of count variable.
YourtriggerConditionshere | Change the value of Scene Variable "Count" = Set to 4
Trigger Once | Start/Reset Scene Timer "Loop"
Scene Variable "Count" > 0 | Change the text of Title: add "A"
Scene Timer "Loop" >= 2 seconds | Start/Reset Scene Timer "Loop"
Trigger Once | Change the value of Scene Variable "Count" = Subtract 1
The initial event will start your loop.
The second event will add your “A”, and restart the loop.
You might even be able to merge it to 1 event and one subevent, but I’m too tired to optimize a bit.
Overall, keep in mind that all events are evaluated in a single frame, every frame. So the repeat is doing all of the actions in a single frame (or at least trying to).
Ok if this is expected behavior, i understand.
For Wait thanks for the example, but my problem was about API calls. This was my test code to see if it was my work or a GDevelop behavior
So i can’t sequence calls that way and i guess i’ll have to work on a callback solution to counter this effect.
I think there is some work being done to make that type of async callback more supportable. @arthuro555 might be able to correct my memory
You also might be better off using a while event instead of a repeat, but I can’t think of a good example.
Tbh callback is fine. Like for tweens, i think it’s also a good way to make things, it’s readable.
But i also think sequencing Async calls can be a topic.
Maybe a specific loop supporting this ? I don’t know.
I’m still not quite sure I understand your motivation. I personally don’t like the wait. There are times where it’s useful but I usually use a timer.
I’m wondering if you were expecting something like this would do.
It’s not about the wait, it’s about async Actions and loops. Wait was an easy example but there are way more cases.
There are two way to think things :
- Async, so you have everything written on your main flow, and you know things will wait (like the Wait)
- Callback, where start and end are separate and you need to test when the ends come (like for Tweens with “Tween has finished”)
The thing is : loops run all the Actions in one go even if they are async, so it breaks the sequence of things bc all of the async Actions will run simultaneously instead of one by one, the thing i thought.
So, for now, the only wait to deal with async and loops is to make callbacks. Which is fine, but i also like the async writting.
Yeah, we were discussing adding some sort of toggle on loop events to allow them to asynchronously await pending async tasks from their body to have finished before the next iteration, but, uhm, nobody seems to be interested in implementing any of this
I’ve lead the development of everything async (in fact, appart from some changes by 4ian from the code reviews of my PRs, I think I am the only one who worked at all on asynchronous features), but between high school exams, the community seemingly not being that interested in async actions, my work being monetized by the GDevelop company without me getting a single penny out of it (which is understandable but still a motivation killer), being alone on the task, and feeling my side project THNK is something more interesting for me and for the community to work on for now, I am not very motivated to finish what I originally set off to do…
I’d be happy to help if you want to contribute that kind of feature, though!
Async is a tough topic. And congratulations for all of what you achieved. It works very well and it’s very easy to work with.
Loop system is also a big topic, so when you have to manage both, i understand that not many of us are brave enough to start the adventure
On my side, i did a workaround, which is a callback system, and it’s also a great method. So i think you can focus on what really matter : your exams !