Ajax funny loop(resolved)

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Ajax funny loop(resolved)

Post 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????
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Ajax funny loop

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Ajax funny loop

Post 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.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Ajax funny loop(resolved)

Post by hallsofvallhalla »

it was the switchon setting..don't ask... but it works now!!!!!!!!!
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: Ajax funny loop(resolved)

Post 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.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Ajax funny loop(resolved)

Post 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
Post Reply

Return to “Advanced Help and Support”