For the - 9.
Never forget that object with UID=0 exists. In this case the purple one has UID = zero. Without setting it to -9, the purple colour will not work if it is the first colour accessed by the touch.
I could have deleted the first instance of color in the layout editor, so the first color gets a different UID then zero. But, construct tends to pack the UID's again in the layout editor, so that zero can/will show up again.
I could have added a fake sprite to the layout at the very start, right after making the new project. Now i am sure that this sprite will have UID=zero. And not ever touching it will keep that UID=zero on that sprite. But how do i explain this in a little/short example.
Better is to make the code account for a possible UID = zero.
So, now, if i set previousTouched to - 9. And the first touch goes over the purple one, then the caught UID (zero) is different then -9, or, there is a change in the situation. We got to act.
Also, in this case, when i set the default stat of previousTouched to any existing color UID, the color will not work when touched as first colour.
So, there are 2 things playing here.
1/ I only want to act if the touch is over a different color then it is over in the previous tick
2/ i only want the color that the touch (when touching) is over to go in the state 'touched' (boolean = true). All other colors must go in the state untouched (boolean = false)
There can be only one color with boolean 'touched' = true. I am sure of that.
Therefor, if i (before changing anything in that state) set previousTouched to the UID of the 'touched one', then i store the UID of the color that had the state 'touched' in the previous tick (event 5)
As long as the state 'touched' is not changed (and i will change it in event 7, later on) , it reflects the previous tick.
Now, in the current tick, things could be changed. I first pick the color that touch is now/at this moment over. And that can be a different color then in the previous tick.
ONLY if its UID is different (not the same as) then the one in the previous tick (previousTouched) i start the timer that is changing colors. (event 8)
I need only the color that the touch is over to be in the state of 'touched'. I could make some complicated inverse or else condition to archive that. But it is a LOT more simple to just set them all in the state 'untouched'. And then set only the one, that has the touch over it, to 'touched'. You see ?
Event 6 just sets them all to 'untouched' ( = boolean touched = false)
Event 7 picks that only one the touch is over and sets its state to 'touched' ( = boolean touched = true)