Activity › Forums › Adobe After Effects Expressions › Trigger at marker
-
Trigger at marker
Posted by Darren Lee on June 11, 2019 at 3:51 pmIs there a method for triggering a function call once when hitting a marker?
I found Dan Ebberts’s script: https://www.motionscript.com/design-guide/marker-sync.html
But it seems to call multiple times after or before a marker
I want something like:function markerTriggered () {
//Trigger once
}if (nearestMarker) {
markerTriggered();
}Darren Lee replied 6 years, 10 months ago 2 Members · 6 Replies -
6 Replies
-
Kalleheikki Kannisto
June 12, 2019 at 6:06 amYou want to include the marker’s time there and compare to current time. While you should be able to do it by checking if marker time equals current time and running the function if so, might be more foolproof to check whether current time is equal or more than marker time and current time minus one frame is less than, and if both conditions are true then run function.
Kalleheikki Kannisto
Senior Graphic Designer -
Darren Lee
June 12, 2019 at 8:49 amThanks for you reply, I should probably give more detail on what I’m trying to achieve
I’m using the script from here https://forums.creativecow.net/docs/forums/post.php?forumid=227&postid=37186&univpostid=37186&pview=t to shuffle an array of numbers.
I have the below on a text Source layer, but I want it to shuffle every time it hot a marker, and stay shuffled
I can achieve this with something like:
if (time == 1) {
shuffle(a);
“[“+a.toString()+”]”;
}But then the array is reset immediately afterwards because it’s being set every frame
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;// While there remain elements to shuffle...
while (0 !== currentIndex) {// Pick a remaining element...
randomIndex = Math.floor(random() * currentIndex);
currentIndex -= 1;// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;}
return array;
}var a = new Array(20, 30, 40);
shuffle(a);
"["+a.toString()+"]";
-
Kalleheikki Kannisto
June 12, 2019 at 10:03 amOk, in that case you want to count the number of markers that you have passed and use that number (marker index) for randomseed. Expressions don’t have a memory of what has happened in earlier frames, so you have to calculate the shuffle for every frame. The same randomseed will ensure the random calculation is the same random calculation. So you would change that at every marker.
A bit of an inconvenience is that the nearest marker can be before or after current time, so you have to check whether the marker time is after current frame, and if so, subtract one to get the index of the last marker passed.Kalleheikki Kannisto
Senior Graphic Designer -
Darren Lee
June 13, 2019 at 10:15 amThanks for this, what that might look like in the code? Something like this?:
randomIndex = Math.floor(randomSeed() * currentIndex); -
Kalleheikki Kannisto
June 13, 2019 at 2:19 pmSomething like this
nMarker = thisComp.marker.nearestKey(time);
mTime = nMarker.time;
mIndex = nMarker.index;
if (mTime>time){
mIndex--
}
seedRandom(mIndex,true);Kalleheikki Kannisto
Senior Graphic Designer
Reply to this Discussion! Login or Sign Up