我正在JavaScript中编写这个非常奇妙的游戏,但是每次运行时我只写了一个函数的一部分崩溃。JavaScript函数在每次运行时崩溃
所以我想知道,这只是为了运行在for循环或我在某处犯了语法错误吗?
这是代码;它取自一个函数,但这是导致它崩溃的部分。
for (zloop=min_houses_per_block; zloop<(house_number+1); zloop++)
{
if (zloop>0)
{
city_block_array[first][second].house_array[zloop].width =
(min_house_width+(((max_house_width-min_house_width)/house_width_slots)*(Math.floor(Math.random()*house_width_slots))));
city_block_array[first][second].house_array[zloop].height =
(min_house_height+(((max_house_height-min_house_height)/house_height_slots)*(Math.floor(Math.random()*house_height_slots))));
if (zloop=1)
{
x_number=(block_width-(house_threshold*2))-city_block_array[first][second].house_array[zloop].width;
min_house_x=house_threshold
city_block_array[first][second].house_array[zloop].x =
(min_house_x+(((x_number)/house_x_slots)*(Math.floor(Math.random()*house_x_slots))));
}
city_block_array[first][second].house_array[zloop].x=6000;
city_block_array[0][0].house_array[1].x=6000;
}
}
没有if (zloop=1)
部分它运行良好。
当然是可以简化.. – 2013-01-23 22:17:27
它的JavaScript告诉你缩进你的代码;) – PeeHaa