Page 1 of 1

Ajax funny loop(resolved)

Posted: Fri Feb 18, 2011 3:26 am
by hallsofvallhalla
in my farm game, i have it where each person has their own farm, or block, it uses ajax to pull the map but when I use this code

Code: Select all

var plants = ajaxRequest.responseText.split("/");
				var totalplants = plants.length;
				
				
				for(i=0;i<totalplants;i=i+3)
				{
					
				
				planted[counterdraw]=new Sp_Sprite();	
				planted[counterdraw].setImage("images/plants/" + plants[png] + ".png",32,32,2); 
				planted[counterdraw].setXlimits(12, 455);
				planted[counterdraw].setYlimits(3, 520);
				planted[counterdraw].setFrame(0);
				planted[counterdraw].setAnimation(0);
				planted[counterdraw].draggable = false;
				planted[counterdraw].switchOn();
				planted[counterdraw].moveTo(plants[leftpos],plants[toppos]);
				planted[counterdraw].setZ(1);
				counterdraw = counterdraw + 1;	
				leftpos = leftpos + 3;
				toppos = toppos + 3;
				png = png + 3;
it throws the plants where they should be for a milisecond then
it does a contiunally loop and throws the plants at top 300000000000000000000px; left 3000000000000000000000000px

if I change the

Code: Select all

planted[counterdraw].moveTo(plants[leftpos],plants[toppos])
;

to

Code: Select all

planted[counterdraw].moveTo(100,100);
it works great...why would using an array cause it to loop like that and readjust my plants????

Re: Ajax funny loop

Posted: Fri Feb 18, 2011 3:48 am
by Xaleph
Maybe you dont provide a key in the array? The split splits OK, but does not assign 12 to Val if you have something like: value1/123/value2/413

Re: Ajax funny loop

Posted: Fri Feb 18, 2011 4:08 am
by hallsofvallhalla
i checked all the values with a alert. they all come out fine. It isn't till after the loop ends that it changes all the values and messes up.

Re: Ajax funny loop(resolved)

Posted: Fri Feb 18, 2011 7:48 pm
by hallsofvallhalla
it was the switchon setting..don't ask... but it works now!!!!!!!!!

Re: Ajax funny loop(resolved)

Posted: Fri Feb 18, 2011 8:29 pm
by Chris
What browser you using?

I found it funny when I tried making a script that retrieved over 1000 records from a database and put them in an array in JavaScript. I made a function that allowed the records to be ordered by the values ascending and descending. It ended up that most browsers wouldn't order them in the right order when there were too many records to loop through. I ended up making it loop 5 times. This worked with consequences, according to IE z still came before a in the alphabet, FireFox had a lot of bother, Chrome did alright. Safari was like WTF?!? and Opera worked perfect.

Re: Ajax funny loop(resolved)

Posted: Fri Feb 18, 2011 9:26 pm
by hallsofvallhalla
wow thanks for that tip. Good thing I just happened to break everthing up by category. Like plants is one array, items another, ect....

Also I am pulling from one field for the entire garden. It is a text feild that is broken up by /...so two plants picture and position will be 300/200/1/100/250/3