Page 1 of 1

My custom code is not working HELP ME!

PostPosted: Wed Oct 14, 2009 11:25 pm
by a2z
I need a counter that displays the amount of times the player has hit a fryer but my code isnt working :shazbot:

I have created a dynamic text box with an instance name 'deaths_txt', placed it in a new layer on the main timeline (so that it is displayed on all of my levels/screens), then I went back to the 'initialization' frame where the majority of the code is; this is also where the "//dangerous surfaces" code is. This is where I would presume a counter for the amount of deaths could be made...

the code I added is in Bold

//## Dangerous surfaces
var deaths = 0;

for (i=0; i<mcLevel.fryArray.length; i++){
if ( mcLevel.fryArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ){
//mcLevel.mcPlayer.x = safeSpot.x;
//mcLevel.mcPlayer.y = safeSpot.y;
xMove = 0;
yMove = 0;
grounded = false;
touchingSlope = "not";
dying = true
if(dying == true); {
deaths += 1;
deaths_txt.text = string(""+deaths+"");
}

}
}

My code doesn't work :shazbot: ! all it does is add 1 the first time you die/hit a fryer, and doesnt add anymore on the other times you hit a fryer?! It just stays at 1 :cry: .
I have tryed a few variations ALL with the same effect.

Anyone know a solution

please :shock:?

Re: My custom code is not working HELP ME!

PostPosted: Thu Oct 15, 2009 10:32 am
by SophieH
did you actually add 'var deaths = 0;' right after '//## Dangerous surfaces'?

because if memory serves me correctly thats inside an EnterFrame function, you should initialise the variable outside of any functions really :)

also you might have to change the other code to something like this:

for (i=0; i<mcLevel.fryArray.length; i++){
if ( mcLevel.fryArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ){
//mcLevel.mcPlayer.x = safeSpot.x;
//mcLevel.mcPlayer.y = safeSpot.y;
xMove = 0;
yMove = 0;
grounded = false;
touchingSlope = "not";
if(dying == false); {
deaths += 1;
deaths_txt.text = string(""+deaths+"");
}
dying = true
}
}

as I think 'dying' returns true the whole time the dying animation is playing (but its been a while since I've looked at the death code so I may be wrong)

Re: My custom code is not working HELP ME!

PostPosted: Thu Oct 15, 2009 1:04 pm
by a2z
Moved "var deaths = 0;" to line 1

Works perfectly ;) thx GirlFlash yay :shake:

Re: My custom code is not working HELP ME!

PostPosted: Sat Oct 17, 2009 9:55 am
by SophieH
no worries, I'm glad I could help :)

Re: My custom code is not working HELP ME!

PostPosted: Fri Jun 18, 2010 9:41 am
by tiffanyyu
placed it in a new layer on the main timeline (so that it is displayed on all of my levels/screens), then I went back to the 'initialization' frame where the majority of the code is http://www.tiffanyesale.com/tiffany-necklaces.html