
While() loop time out assistance•
Hey everyone, (sorry in advance for the wall of text) I've been working on this expression now for a few days, and everything works fine until I un-comment the very last few lines where I start a while() loop. I know I've created an infinite loop somewhere, I just can't find the reasoning behind it. Basically this script generates a random number and compares it to 2 previous values in time to determine whether or not it is the same value at that point in time. If it is the same value, It offsets the seed until the value it generates is unique to the 2 values before it. Probably there is a better way of achieving this goal, but I am more interested in why the things I write don't work, so I can learn from my mistakes. So any help in that regard would be excellent. Thanks for your time! (the following expression goes into a Slider expression control) //TIME PARAMATER VARIABLE DECLARATIONS
•
I don't have After Effects on my machine right now, but the problem is most likely that the "same"-variable is not seen as a global variable by the functions, so they are creating their own variable with the "same" name, the while() loop never sees the updated version of the variable. try decalring like this, I think that should work: global same=false;
•
Thanks for the reply Are you sure that global is a javascript keyword? It wasn't recognised and caused another error. Still, I found the source of my error, if you're still interested. I found out the hard way that negative seeds will not generate random numbers. So at time = 0, when I was testing the previous values at time= -1, I was reading a negative seed which always returned the same value regardless of time. (-1, -2, -3 etc always returned 2 for example.) Thus causing an infinite loop in the expression. I'm still experimenting the best way to fix this, but the solution I came up with is to declare my seed as: seed = Math.abs(...)
|