mattal999 Posted September 26, 2007 Share Posted September 26, 2007 hi, i get an error message sometimes, when the car has gone to the finish line: "'pos[...]' is null or not an object?" my code now: <html> <head> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> <script language="JavaScript"> pos = new Array(); pos[0] = "60,60"; pos[1] = "65,60"; pos[2] = "70,60"; pos[3] = "75,60"; pos[4] = "80,60"; pos[5] = "85,60"; pos[6] = "90,60"; pos[7] = "95,60"; pos[8] = "100,60"; pos[9] = "105,60"; pos[10] = "110,60"; pos[11] = "115,60"; pos[12] = "120,60"; pos[13] = "125,60"; pos[14] = "130,60"; pos[15] = "135,60"; pos[16] = "140,60"; pos[17] = "145,60"; pos[18] = "160,60"; pos[19] = "165,60"; pos[20] = "170,60"; pos[21] = "175,60"; pos[22] = "180,60"; pos[23] = "185,60"; pos[24] = "190,60"; pos[25] = "195,60"; pos[26] = "200,60"; pos[27] = "205,60"; pos[28] = "210,60"; pos[29] = "215,60"; pos[30] = "220,60"; pos[31] = "225,60"; pos[32] = "230,60"; pos[33] = "235,60"; pos[34] = "240,60"; pos[35] = "245,60"; pos[36] = "250,60"; pos[37] = "255,60"; pos[38] = "260,60"; pos[39] = "265,60"; pos[40] = "270,60"; pos[41] = "275,60"; pos[42] = "280,60"; pos[43] = "285,60"; pos[44] = "290,60"; pos[45] = "295,60"; pos[46] = "300,60"; pos[47] = "305,60"; var step = 0; var laststep = pos.length; var timer; function animate() { step++; if(step == laststep) step = 0; var newpos = pos[step].split(","); rand = Math.floor(Math.random()*47+1) % 4; var newpos = pos[step + rand].split(","); window.document.all.ball1.style.left = parseInt(newpos[0]); window.document.all.ball1.style.top = parseInt(newpos[1]); var thatpos = pos[step].split(","); rand = Math.floor(Math.random()*47+1) % 4; var thatpos = pos[step + rand].split(","); window.document.all.ball2.style.left = parseInt(thatpos[0]); window.document.all.ball2.style.top = parseInt(105); timer = setTimeout("animate()",100); if(newpos[0] >= 301) window.location="won.php"; if(newpos[0] >= 301) clearTimeout(timer); if(thatpos[0] >= 301) window.location="lost.php"; if(thatpos[0] >= 301) clearTimeout(timer); } function stopAnimation() { clearTimeout(timer); } </script> </head> <body onload='animate();' bgcolor="#333333"> <span id="he" style="position:absolute; visibility: visible; top:18; left:28; width:303; height:190; z-index:2"><img src='../My Pictures/bgg.bmp' width="344" height="142"></span><span id="ball1" style="position:absolute; visibility: visible; top:60; left:60; width:32; height:32; z-index:2"> <img border=0 width=32 height=15 src="../My%20Pictures/car.bmp"></span><span id="ball2" style="position:absolute; visibility: visible; top:90; left:60; width:32; height:32; z-index:2"> <img border=0 width=32 height=15 src="../My%20Pictures/car.bmp"></span> Help plz Quote Link to comment Share on other sites More sharing options...
php_tom Posted September 27, 2007 Share Posted September 27, 2007 Seems to work for me... I get two images 'racing' on the screen, when they reach the other side, it redirects to 'won.php'. So I'm not sure what the problem you're having is. Maybe you need "var pos = new Array();" ? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted September 27, 2007 Author Share Posted September 27, 2007 try running it 5 times or more in frontpage or somthing that will show errors. it doesnt do it all the time, just sometimes Quote Link to comment Share on other sites More sharing options...
emehrkay Posted September 27, 2007 Share Posted September 27, 2007 the problem is that step is global and never reset. so after the first time it is run, it is still whatever it was the last time it was run. and assign your arrays like this if your're not going to use all of the array features var pos = [ '66,66', '67,67' //and so on ]; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.