Forum Topic: Phantom problem, no error thrown

(89 views • 9 replies)

This topic is 1 page long.

<< < > >>
Questioning

musicdemon

Reply To Post Reply & Quote

Posted at: 6/29/09 03:16 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

Hello, everyone :) I'm using AS3 and I've got an interesting situation. My game is mostly complete (roughly 90% done). However, there is one oddity that I can't overlook. Orbs are supposed to fall from the top of the map, then the user collects them, and points are added to the score. The strange thing is that a small percentage of the falling orbs, in a seemingly random pattern, simply stop at random points on the screen. The game continues on normally, but the orbs that are stuck aren't collectable and can only be gotten rid of by restarting the game. Has anyone encountered something like this before?


None

Woadraiders

Reply To Post Reply & Quote

Posted at: 6/29/09 03:21 PM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

My guess is that they were given a NaN for one of thier coordinates sometime while falling, or SOME field on them is NaN.

Mibbygames.com
panterA

BBS Signature

None

musicdemon

Reply To Post Reply & Quote

Posted at: 6/29/09 03:31 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

I think you're right about that. Here's the section of the function that is the likely problem:

c = collectibleArray.length - 1;
			var powerupCollectible:PowerupCollectible;
			while (c > -1)
			{
					powerupCollectible = collectibleArray[c];
					powerupCollectible.descend();

I think that as soon as the next powerup comes into the array (every 1.5 seconds via a Timer object), the movement of the last object stops. Is there an alternate way I could have my powerups move down the screen using that array?


None

Woadraiders

Reply To Post Reply & Quote

Posted at: 6/29/09 03:33 PM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

Yeah, I'd use a for-loop instead.

for(var i:Number = 0;i< collectibleArray.length;i++)
{
    collectibeArray[i].descend();
}

Mibbygames.com
panterA

BBS Signature

None

musicdemon

Reply To Post Reply & Quote

Posted at: 6/29/09 03:50 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

Yeah, a for loop is much more efficient there, I suppose. However, it didn't seem to resolve my issue. I waited before grabbing the powerup and, sure enough, if you grab the "older" of two powerups coming down the screen, the more recent powerup stops. Apparently, the fundamental problem is still there. Here's the entire for loop this time:

var powerupCollectible:PowerupCollectible;
			for(var c:Number = 0; c < collectibleArray.length; c++)
			{
				powerupCollectible = collectibleArray[c];
				collectibleArray[c].descend();
				
				if ( PixelPerfectCollisionDetection.isColliding( avatar, powerupCollectible, this, true ) ) 
				{
					removeChild(powerupCollectible);
					collectibleArray.splice(p, 1);
					
					collectibleAcquired();
				}
			}

None

Woadraiders

Reply To Post Reply & Quote

Posted at: 6/29/09 04:06 PM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

Try this code exactly as it is, don't put in your powerCollectible reference stuff, it's just one more possible source of the problem that we'd have to look through.

for(var c:Number = 0; c < collectibleArray.length; c++)
			{
				collectibleArray[c].descend();
				
				if ( PixelPerfectCollisionDetection.isColliding( avatar, collectibleArray[c], this, true ) ) 
				{
					removeChild(collectibleArray[c]);
					collectibleArray.splice(c, 1);
					
					collectibleAcquired();
				}
			}

Mibbygames.com
panterA

BBS Signature

None

musicdemon

Reply To Post Reply & Quote

Posted at: 6/29/09 04:21 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

Thank you so much! It's working properly now. Apparently, that variable wasn't needed and was only mucking things up. Thanks, again :)


None

Woadraiders

Reply To Post Reply & Quote

Posted at: 6/29/09 04:22 PM

Woadraiders DARK LEVEL 11

Sign-Up: 11/11/07

Posts: 561

Well no, your splice function was also wrong. You had collectibeArray.splice(p, 1); but there was no 'p' variable.

Mibbygames.com
panterA

BBS Signature

None

musicdemon

Reply To Post Reply & Quote

Posted at: 6/29/09 04:31 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

Oh, I didn't catch that the first time. Thanks for the extra set of eyes!


None

musicdemon

Reply To Post Reply & Quote

Posted at: 7/4/09 12:41 PM

musicdemon NEUTRAL LEVEL 07

Sign-Up: 06/04/09

Posts: 17

The suggested loop format worked without a problem except when I tried to add in collision detection. This error gets thrown when the *most recent* powerup is acquired before another one has a chance to spawn: "TypeError: Error #1010: A term is undefined and has no properties."

Here's the code I've been using:

for(var c:Number = 0; c < collectibleArray.length && isGamePaused == false; c++)
{
	collectibleArray[c].descend();
				
			if ( PixelPerfectCollisionDetection.isColliding( avatar, collectibleArray[c], this, true ) ) 
				{
					removeChild(collectibleArray[c]);
					collectibleArray.splice(c, 1);
					
					collectibleAcquired();
				}
				
				if( collectibleArray[c].y > 500)
				{
					removeChild(collectibleArray[c]);
					collectibleArray.splice(c, 1);
				}
			}

Any ideas?


All times are Eastern Standard Time (GMT -5) | Current Time: 03:07 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!