On startup of layout (event 1), i place the targets. Because i use a container to pair up text boxes with targets, i got to create them on run time. Because i was to lazy to calculate positions, i prepared some objects in the layout to place the targets on.
Event 7 reads as: if instance variable 'targetUID' of the mover = -1, then pick the mover, and add a random target to the picklist. Move the picked mover to the picked target. At the same time i set 'targetUID' to UID of the choosen target. I reset the 'overlappingTime' of that target. I write that (zero) in the textbox belonging to that target. Since i use containers, picking a target also picks its text box. And, so i can see (and debug what i am dooing) i set the opacity of that choosen target, so it stands out. This event (event 7) will not run again untill 'targetUID' is set to -1 again in event 15. Why -1 and not zero ? Because the UID zero can exist. It is bad coding to take that risk.
Event 9 reads as: Pick the target by its UID (instance variable 'targetUID' of the mover). Add the mover to that picklist when its boolean 'StartedOverlapping' is not true. If the picked target overlaps the picked mover then ... and only the first tick that all this is true ... set 'StartedOverlapping' to true.
So. When the mover overlaps that choosen target (not any other target) set a boolean to true, so we know that from this moment we have to count the time that they are overlapping.
Event 11 is the opposite of event 9. If i set a boolean, i have to unset it somewhere.
So, event 11 reads as: if the boolean 'StartedOverlapping' is set to true and if the mover is not overlapping any target, then pick the mover. And set 'StartedOverlapping' to false.
Also meaning that there can be no more time added in event 13. Done with overlapping = stop the timer.
Event 13 is the counter. It reads as: if 'StartedOverlapping' is true, then pick the mover. If that mover is overlapping any target, then add that target to the picklist. 'StartedOverlapping' is only set (in event 9) when the target is the choosen target, so i can safely asume that any target picked here is the choosen target. When all this happen, add dt to the timer every tick. And show that time in the (due the container) picked textbox.
Event 15 just sets instance variable 'targetUID' of the mover to -1when the MoveTo plugin says it reached destiny. With 'targetUID' = -1, event 9 can again find a new target. And it all starts all over again.
Basicaly most coding in C2 works this way: pick an object when something is true. Add another object to that picklist when something is true. Make actions that work on the picked objects.