Here are some topics I found on the matter:
There are probably more. The gist of what happens is the wait delays the following actions till later, the function ends, and when the actions finally run the parameters are no longer there.
The cleanest solution is probably not to use that wait 0 trick at all. The events in your pic can be made like this and operate the same.
every 4 seconds
--- create sprite at random location
--- call function "detect"
on function "detect"
--- sprite: set blend to source out
But in the context of what you want to do you can pass the uid to the function and you can pick the new sprite "by uid" and you can pick the rest of the instances with "pick all". To make things simpler a family can be used like below:
// family "otherSprite" with object type sprite
every 4 seconds
--- create sprite at (random(640),random(480))
--- call function "detect" (sprite.uid)
on function "detect"
sprite: pick by uid function.param(0)
while
sprite overlaps otherSprite
--- sprite: set position to (random(640),random(480))
And just for completeness if you want all the instances to be picked you can set variable or enable a group to run events. There's an example for zordering in the bottom of the post here: