Jump to content

Ajax problem.


vytas
 Share

Recommended Posts

I'm working on this game coded in JavaScript with ASCII graphics :) but i have a problem i now get my data from the server threw XML and then i try to render them if the next info get's to the (client) browser i delete the old position and render the new ones something like this:Client request info on players -> Server sends info on players -> Client deletes old rendering -> Client makes a new renderingBut while the browser (client) is busy doing that it loses the ability to move. I'd like to know if anyone has a solution to that here's the code. Not bad eh for a 15year old. :)

<html><head><title>MOMSG</title><style type="text/css">div {font-family: verdana;font-size: 10px;text-align: center;}.wall {background-color: #EFEFEF;border-color: #CCCCCC;border-width: 1px;border-style: solid;position: absolute;height: 19px;width: 19px;}.gameover {background-color: transparent;border-width: 2px;border-style: solid;position: absolute;visibility: hidden;left: 200px;top: 200px;height: 50px;width: 500px;font-family: "Impact";font-size: 100px;}.character {background-color: #DD9999;/*#9999DD*/;border-color: #000000;border-width: 1px;border-style: solid;position: absolute;height: 19px;width: 19px;}body { background-color: white }#controller {background-color: #EFEFEF;border-color: #CCCCCC;border-width: 1px;border-style: solid;font-family: verdana;font-size: 10px;text-align: center;}</style><script language="JavaScript">var objCount = 0;var xmlHttp;var deletethis = document.getElementById("wegermee");delete delethis;startTile = {x: 1, y: 28};var map = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1],[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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ore = [];var ystore = [];var playerstore = [];yOffset = 20;tileSize = 20;map[2][1] == 3;var shotcount = 0;var curDir = "up";var removetimer = 1;setInterval("removetimer--", 200);var walktimer = 0;setInterval("walktimer--", 80);var playerobject = [];// function myfocus()//{// var myinputa = document.getElementById("controller");//  myinputa.focus();// }// setInterval("myfocus()", 500);//function newObj(type, x, y) {name = type+"_"+objCountchar = "(!)";writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px'>"+char+"</div>";objCount++;document.body.innerHTML += writeThis;return eval(name);}function drawPlayers() { for (i = 0; i < ystore.length; i++) {	playerobject[i] = newObj("character",xstore[i],ystore[i]);	map[ystore[i]][xstore[i]] == 3;	playerMap[ystore[i]][xstore[i]] == playerstore[i]; }}function removePlayers() { for (i = 0; i < ystore.length; i++) {	delete playerobject[i];	map[ystore[i]][xstore[i]] == 0;	playerMap[ystore[i]][xstore[i]] == 0; }}function stripPlayer(info) { removePlayers();xstore = [];ystore = [];playerstore = []; var players = info.getElementsByTagName("player"); for (i = 0; i < players.length; i++) {	xstore.push(players[i].childNodes[0].childNodes[0].nodeValue); } for (j = 0; j < players.length; j++) {	ystore.push(players[j].childNodes[1].childNodes[0].nodeValue); } for (k = 0; k < players.length; k++) {	playerstore.push(players[k].childNodes[2].childNodes[0].nodeValue); } drawPlayers();}function makeObj(type, x, y) {// <div class="type" style="top: xpx; left: ypx" />if (type=="wall") {name = type+"_"+x+"_"+y;char = "=";} else {name = type+"_"+objCountchar = "(!)";}writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px'>"+char+"</div>";objCount++;document.write(writeThis);eval(name).x = x;eval(name).y = y;eval(name).health = 100;return eval(name);}function assessMap() {for (y=0; y<map.length; y++) {for (x=0; x<map[0].length; x++) {if (map[y][x] == 1) {makeObj("wall", x, y);}}}}assessMap();var mainChar = makeObj("character", startTile.x, startTile.y); //mainChar now acts as a reference to the div object for the character.function assessKeys(evt) {move = false;x = mainChar.x;y = mainChar.y;key = evt.keyCode;if (key == 97) {//LEFTmove = true;curDir = "left";x -= 1;} else if (key == 119) {//UPmove = true;curDir = "up";y -= 1;} else if (key == 100) {//RIGHTmove = true;curDir = "right";x += 1;} else if (key == 115) {//DOWNmove = true;curDir = "down";y += 1;} else if (key == 32) {// SPACE BAR = Shootvar newshot = shoot(mainChar, curDir);}if (move == true && walktimer <= 0) {if (map[y][x] == 0) {mainChar.style.left = x*tileSize + xOffset;mainChar.style.top = y*tileSize + yOffset;mainChar.x = x;mainChar.y = y;walktimer = 1;}}testDirections();}function shoot(obj, directshoot){ if (directshoot == "right") {  for (xto = obj.x; xto < obj.x+10; xto++) {   if(map[obj.y][xto] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[obj.y][xto]);    break;   }  } } else if (directshoot == "left") {  for (xto = obj.x; xto > obj.x-10; xto--) {   if(map[obj.y][xto] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[obj.y][xto]);    break;   }  } } else if (directshoot == "up") {  for (yto = obj.y; yto > obj.y-10; yto--) {    if(map[yto][obj.x] == 3) {     name = "shot"+shotcount;      alert("u hit : "+playerMap[yto][obj.x]);     break;    } else if (map[yto][obj.x] == 1) {	break;    }  } } else if (directshoot == "down") {  for (yto = obj.y; yto < obj.y+10; yto++) {   if(map[yto][obj.x] == 3) {    name = "shot"+shotcount;     alert("u hit : "+playerMap[yto][obj.x]);    break;   } else if (map[yto][obj.x] == 1) {	break;   }  } }}function getHit (obj) { health = obj.health; health -= 20; obj.health = health; if (obj.health <= 0) {	mainChar.x = 1;	mainChar.y = 28;	obj.style.top = y*tileSize+yOffset;	obj.style.left = x*tileSize+xOffset;	var gameover = document.getElementById("gameover");	gameover.style.visibility =  "visible";	setTimeout("gameover.style.visibility = 'hidden'", 2000);	obj.health = 100; } document.body.style.backgroundColor = "red"; setTimeout("document.body.style.backgroundColor = 'white'", 50);}function ajaxFunction(){	var xmlHttp;	try 	 {  // Firefox, Opera 8.0+, Safari 	  xmlHttp=new XMLHttpRequest();  	} catch (e)   { 	 // Internet Explorer  	try    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }  catch (e)    {    try      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }    catch (e)      {      alert("Your browser does not support AJAX!");      return false;      }    }  }  xmlHttp.onreadystatechange=function()    {    if(xmlHttp.readyState==4)      {      player = xmlHttp.responseXML;      stripPlayer(player);      }    }  xmlHttp.open("GET","coords.xml",false);  xmlHttp.send(null);  }setInterval("ajaxFunction()",1000);function testDirections() {x = mainChar.x;y = mainChar.y;canUp = true;canDown = true;canLeft = true;canRight = true;if (map[y-1][x] == 1) {canUp = false;}if (map[y+1][x] == 1) {canDown = false;}if (map[y][x-1] == 1) {canLeft = false;}if (map[y][x+1] == 1) {canRight = false;}document.title = "Up: "+canUp+", Down: "+canDown+", Right: "+canRight+", Left: "+canLeft;}</script></head><body onKeyPress="assessKeys(event)"><div id="gameover" class="gameover"><h1><font color="red">GAME OVER</font></h1></div><div id="tester"></div></body></html>

This might be a hard one for you guys at w3schools but i now u can do it.

Link to comment
Share on other sites

There's no way you're going to be able to speed up a game based on HTTP requests.If this isn't a game that has to be continuously updated you can maybe just play the game on client-side the whole time, and then have a "save" button that saves the information on the server when the player is done.

Link to comment
Share on other sites

No that's the point it has to be constanly updated. I have been trying to set the request at a lower rate to give the client more time to render even if u set the Interval to 10 secs you're still unable to move which is really strange. look at it yourself change the Interval of the ajaxfunction to 10000 and try to play the game. BTW it's only Internet Explorer compatible because of the onkeypress at <body>Try to move with the WASD key's. Maybe ul know what's wrong.

Link to comment
Share on other sites

If the function isn't responding it might not be the AJAX request that's stopping it, there may be an error in the program.Anyways, if you're developing this for Internet Explorer it's not going to be easy to help you. You haven't provided a link to the game, so I can't test it.

Link to comment
Share on other sites

It's currently at : here (free host)But i noticed something in my title bar i show if i can move up or down but when i move with the WASD keys the up = true or false changed same with the down right and left, so it's doing something good only not replacing the character which is weird because that allways worked.

Link to comment
Share on other sites

Wy did u think id post it here if everything worked. But everything did as it supposed to untill i added these 3 functions then my char stopped moving.

function newObj(type, x, y) {name = type+"_"+objCountchar = "(!)";writeThis = "<div id='"+name+"' class='"+type+"' style='left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px'>"+char+"</div>";objCount++;document.body.innerHTML += writeThis;return eval(name);}function drawPlayers() { for (i = 0; i < ystore.length; i++) {	playerobject[i] = newObj("character",xstore[i],ystore[i]);	map[ystore[i]][xstore[i]] == 3;	playerMap[ystore[i]][xstore[i]] == playerstore[i]; }}function removePlayers() { for (i = 0; i < ystore.length; i++) {	delete playerobject[i];	map[ystore[i]][xstore[i]] == 0;	playerMap[ystore[i]][xstore[i]] == 0; }}

So obviously the problem is in there

Link to comment
Share on other sites

You appear to be using AJAX synchronously:

xmlHttp.open("GET","coords.xml",false);

That line is telling the scripting engine to wait until the response comes back from GETting "coords.xml" before it goes on to the next line. If you want to run that asynchronously, you might start by changing that line to this:

xmlHttp.open("GET","coords.xml",true);

Link to comment
Share on other sites

I have concluded that the newObj function causes the problems only i don't know wy.So i need you're help figuring that out il guess it has something to do with the div creation.best of luck, Vytas

Link to comment
Share on other sites

I have replaced the newObj function to this

function newObj(type, x, y) {name = Math.random()*1000000;char = "(!)";mystyle = "left: "+Number(x*tileSize+xOffset)+"px; top: "+Number(y*tileSize+yOffset)+"px";var newdiv = document.createElement('div');var divIdName = name;newdiv.setAttribute('id',name);newdiv.innerHTML = char;var useobj = document.body.appendChild(newdiv);useobj.style.position = "absolute";useobj.style.left = Number(x*tileSize+xOffset)+"px";useobj.style.top = Number(y*tileSize+yOffset)+"px";useobj.className = type;objCount++;return eval(useobj);}

And know it is working again, i can walk and the players would stil be rendered right.But here's the other problem shoot isn't working anymore any ideas?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...