setTimeout runs asynchronously, it is not blocking. If you want to wait for the timeout to finish, the next "loop iteration" needs to happen in the function callback you are giving setTimeout.
Something like this would work:
turn = 4;
var t = 1;
ourTimeout(allMovies, turn, t);
function ourTimeout(allMovies, turn, t){
AIbutton(allMoves[t-1]);
if(t <= turn)
setTimeout(ourTimeout(allMovies, turn, ++t), 1000);
}
@Alnitak mentions that this line of code:
setTimeout(ourTimeout(allMovies, turn, ++t), 1000);`
needs to be changed to this:
setTimeout(function(){
ourTimeout(allMovies, turn, ++t);
}, 1000);
As @Alnitak states, you can only pass an anonoymous or named function to setTimeout. The trick of passing variables is done as the change above mentions (concept is called a closure).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…