Click to See Complete Forum and Search --> : Random timed function


ck_net_2004
09-03-2004, 04:01 AM
Ive got a function that i want activated
randomly between 2 and 4 secconds using another function.

also what is the key code for the spacebar?

AdamBrill
09-03-2004, 08:25 AM
Is this something like what you are looking for?function test(){
alert("test");
setTimeout("test();", Math.floor(Math.random()*2000)+2000);
}
test();also what is the key code for the spacebar?32

ck_net_2004
09-03-2004, 10:08 PM
Thanks, yes that is pretty much what im looking for.
im making a JS game and i want the enemy to shoot you once
every 2 - 4 secconds. how could i make it so that this function
can be used for many enemys and when their shot with my
kwound() function stop their random shooting patern.

function kwound(enemyid){ // Shoot enemy
var k_enemyid="k_enemy_no" + enemyid + ""; // get enemy id
if (k_ammo==0){ // check for ammo
alert("No Ammo - reload");
}else{
k_ammo-- // minus 1 ammo
document.kbullet.src='files/bullets/Bullet-'+k_ammo+'.bmp'
//update bullet meter
document.getElementById(k_enemyid).style.display = 'none';
//close enemy
}
}