This code for this tutorial is very simple. It consists of one " if " statement. The example shown is 4KB in size.
The "random()" function returns a number between zero and whatever number you put between the parenthesis, here it's 40.
The " if " statement determines if the random number generated by the "random()" function is less than 20.
If the number is less than 20 the playhead loops back to frame 1 without playing the animation.
If the number is equal to or greater than 20 it continues to play the animation.
To guarantee a certain amount of frames/time elapses before the animation has a chance to play, adjust the number of frames before the playhead hits the random code. This will give a loop delay.
Use the " if " condition to set the chance that the animation will play.
The example shows the code checking to see if the number generated (0 to 40) is under 20. This gives it a 50 percent chance of playing.
Note the frame added to the end, frame 16. This helps break up any repetitious blockiness from multiple clip instances like this example.
The blockiness is especially apparent when the code frame number divides readily into the total frames of the movie clip. Like if the code was in frame 5 with the total frames being 10.
You can use several keyframes of the code in different frames to vary the playing chance even more.
For example you could put the code in frame 5 with a 90 percent chance of playing then have another keyframe of code in frame 10 with a 25 percent chance of letting the playhead pass.
The animation would then have a 25 percent chance of playing 90 percent of the time. lol