How to run method without blocking?

I’m pretty sure C++ lets you access variables outside the lambda. So in my above example, I could change foo inside the lambda like:

[foo](){foo += 1;}

I’m going to have to create a separate resource object for keeping track of the tally, because apparently local variables are passed into the closure by value rather than by reference.

I’m not sure of other frameworks that do precisely this, although pretty well any threading library will have a join() statement that waits for another thread to finish before continuing.

Adding a method to tween that pauses until a condition evaluates true could be useful. Maybe a Tween.wait_until_true(callable:Callable). And you could pass in a closure that counts how many signals have been caught. Would be even better if closures could reference variables outside of them.

True, it would be [&foo](){foo += 1;} though, & will capture a reference, otherwise it would be a copy too.

I did not know Godot only captures values, that is a shame, at least there is a warning for it the docs mention, maybe a single-item array will be passed not duplicated, sadly it is hacky territory.

I think evaluate after x signals still wouldn’t catch your use case since it’s x signals from x different objects, might just be too special a case for the tween system alone.

1 Like

Have a look at this project I created just now at https://github.com/belzecue/godot_forum_6109

It’s not exactly what you wanted but I think the approach is the same.

You track your tweens in an array, and each time a tween finishes it calls back to a function that iterates through the array to see if any stored tweens are still running. If not, that checker function emits a final ‘all tweens finished’ signal. Whichever tween is last to finish will always trigger that final signal.

1 Like