I’m trying to get rid of the random function in a slideshow I’m using. the iRnd variable passes the value to loader; I’ve tried to use for (i=0; i<= aImages.lenght, i++) {iRnd=i} but that does not get the job done. I just want to get rid of the random, and get images one by one in the order they’re in the array.
Here’s my code:
function LoadImages()
{
/* Select a random image number and make sure this is not equal to the previous image */
while(iPrev == iRnd)
{
iRnd = Math.floor(Math.random()*aImages.length);
}
/* Show the selected image */
LoadImage(iRnd);
iPrev = iRnd;
};
You’re probably looking for the modulus operator (%) to help you wrap around when you reach the end. This should work for you:
However you should avoid having so many global variables in your code (I’m assuming
aImagesandiRndare both global).