Do…While loop causing fatal crash and I’ve got no idea why, can anybody give any tips?
function randomValue(dir){
if(dir == “height”){
var randomInt = Math.round(random(game.number_tiles/5));
}else{
var randomInt = Math.round(random((game.number_tiles/5)+1));
}
return randomInt;
}
function checkLevelEmpty(){
var currentRandomX = randomValue(‘width’);
var currentRandomY = randomValue(‘height’);
trace('Random X: ‘+currentRandomX+’, Random Y: '+currentRandomY);
if(level[currentRandomY][currentRandomX] != 2){
currentFilledTiles++;
level[currentRandomY][currentRandomX] = 2;
}else{
trace('Try Again!');
}
}
currentFilledTiles = 0;
// generate the random level array with misc placement
do {
checkLevelEmpty();
}
while (currentFilledTiles <= game.number_tiles);
}