So I'm trying to simplify my script from having to use multiple functions with setintervals and clearintervals to have only one function that can be run simultaneously as if it were a bunch of different functions, like an array so the file is not so big. Here is an example of what the script does http://test.719records.com/test/test.html (Page is made to be viewed in 1080P or higher) and here is the script as a whole http://test.719records.com/test/jquery.solari.letters.js
Here is an excerpt of the script that I want to end up being iterated.
//randomize name1 li:1 frames
//until correct character is landed on
var randlet = 0;
function randomizerlet1_1() {
randlet = Math.floor(Math.random() * 156);
timesletrun[0] += 1;
if (masterlet[randlet] == letter[0]) {
$('#flipL1_1').css('background-position', masterlet[randlet]);
clearInterval(intervallet1_1);
} else {
if (timesletrun[0] == 300) {
masterlet[randlet] = letter[0];
$('#flipL1_1').css('background-position', masterlet[randlet]);
clearInterval(intervallet1_1);
} else {
$('#flipL1_1').css('background-position', masterlet[randlet]);
}
}
}
var intervallet1_1 = setInterval(function() {
randomizerlet1_1();
}, 10);
and here would be the second letter in the sequence:
//randomize name1 li:2 frames
//until correct character is landed on
function randomizerlet1_2() {
randlet = Math.floor(Math.random() * 156);
timesletrun[1] += 1;
if (masterlet[randlet] == letter[1]) {
$('#flipL1_2').css('background-position', masterlet[randlet]);
clearInterval(intervallet1_2);
} else {
if (timesletrun[1] == 300) {
masterlet[randlet] = letter[1];
$('#flipL1_2').css('background-position', masterlet[randlet]);
clearInterval(intervallet1_2);
} else {
$('#flipL1_2').css('background-position', masterlet[randlet]);
}
}
}
var intervallet1_2 = setInterval(function() {
randomizerlet1_2();
}, 10);
now there are 38 of these running in total for 1 line and there will end up being 28 lines. I'm sorry my knowledge is not at expert level, I'm still learning, so this might be easy and it might not be but I need to simplify these to one iterated function if its possible. Maybe using a multidimensional array and function arguments? I'm unsure how this code would look.
If this can be simplified I will be creating a tutorial for it and wrapping it into a free 3rd party plugin for people to use on their own personal projects!