function Game(){ var fi = figureSel(it); f = eval(fi + '.position'); var color = eval(fi + '.colorClass'); var posi = f[0]; var i = 0; var t = 0; function Star(){ while(t < 4){ setTimeout(Star, 1000); for (i = 0; i < posi.length; i++){ $(pos(posi[i][0] + t, posi[i][1])).addClass(color); }; t++; }; };
- 1000 * t try. Although t may be 5, I definitely don’t remember. - Jean-Claude
- does not help, does not work - Igor
- the code did not work as I needed, but when I wrote with eval it worked) - Igor
- If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦
|
1 answer
It is necessary to recursively call a function via SetTimeout 4 times, and not to push while in Star, which is called after 1 second, it turns out every time after a second, the Star function is called, in which the cycle four times calls the Star function again and so on
Like that:
function Star() { if (t < 4) { setTimeout(Star, 1000); for (i = 0; i < posi.length; i++) { $(pos(posi[i][0] + t, posi[i][1])).addClass(color); }; t++; }; };
- something didn’t help, it still doesn’t work (( - Igor
- the code inside the conditional operator does not work ( - Igor
- Thank you, everything works, I just did not call the Star () function itself - Igor
|