increase the variable(from 0) till it reaches a predetermined value in a given time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dharamveer
    New Member
    • Sep 2010
    • 1

    #1

    increase the variable(from 0) till it reaches a predetermined value in a given time

    I have made a virtual cricket manager game. In which, a user when plays against another user, a complete match is played and eventally one of the player wins.

    What I need is to slowly increase the score from 0 to the final score say 150, in the mean while change other values as of required.

    This is bieng done to inrease the friendliness of the game and make it more fun with the suspense of total score till the end.(say in 20 seconds)

    I was using AJAX for it, I can store the values in a PHP Array and then display it, so anyways any help in this regard and i would be very grateful to you.

    Thanks in advance

    Code:
    function do_ajax(div,i) 
    	{ 
    		var ajax = new Ajax(); 
    		ajax.responseType = Ajax.FBML; 
    		ajax.ondone = function(data)
    		{ 
    			document.getElementById(div).setInnerFBML(data);
    		}
    		var params={"over":i}; //add parameters as comma separated "param":value
    		ajax.post("http://abcd.com/ajax.php?t=test",params); 
    		if(i<20)
    		{
    	    RefreshAjax(div,i);
    		}
    		else
    			return 1;
    	}
    	
    	function RefreshAjax(div,i)
    	{
    		i++;
    		setTimeout(function() {do_ajax(div,i)}, 1200);	
    	}
    This is the code that I was using but if I try to make it any more fast it completely gets spoilt and starts to lag. It works though. Thanks again
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    whatfor is the ajax call good? do you really need to post the values to the server? in that case the request-response-cyles would become relevant since only 2 requests could be processed at a time - so that it could be that it starts to build a queue of requests ...

    Comment

    Working...