I’m trying to make a basic (non animated) slot machine but am getting an error with stack size.
I’m hoping some one can explain what the cause is =/
My Error :
Uncaught RangeError: Maximum call stack size exceeded
Code:
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback, element){
window.setTimeout(callback, 1000 / 60);
};
})();
var img_array = new Array('fire','life','lightning','rain','snow','sound','sun');
function roll(start_time){
var seconds_passed = new Date().getTime() / 1000 - start_time ;
if(seconds_passed < 3){
slot = 1;
while(slot < 4){
randno = Math.floor(Math.random()*img_array.length);
document.getElementById("slot"+slot).innerHTML = '<img src="'+img_array[randno]+'.png"/>';
slot++;
}
requestAnimFrame(roll(start_time));
} else {
document.getElementById("start").innerHTML = 'Roll The Slots Again?';
document.getElementById("start").onclick = function(){start(); };
}
return false;
}
function start(){
start_time = new Date().getTime() / 1000;
document.getElementById("start").innerHTML = 'Processing......';
roll(start_time);
}
window.onload = function(){
document.getElementById("start").innerHTML = 'Roll The Slots';
document.getElementById("start").onclick = function(){start(); };
}
Where is my mistake ?
This just calls
rollrecursively for three seconds, which will exceed the maximum call stack size:You probably meant: