My custom code is not working HELP ME!

All talk relating to Edward, the Flash platform game engine. (Forum is now locked)

My custom code is not working HELP ME!

Postby a2z » Wed Oct 14, 2009 11:25 pm

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:?
a2z
Newcomer
 
Posts: 3
Joined: Thu Jul 09, 2009 12:03 pm

Re: My custom code is not working HELP ME!

Postby SophieH » Thu Oct 15, 2009 10:32 am

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)
User avatar
SophieH
Site Admin
 
Posts: 76
Joined: Fri Aug 08, 2008 8:01 pm
Location: UK - Europe

Re: My custom code is not working HELP ME!

Postby a2z » Thu Oct 15, 2009 1:04 pm

Moved "var deaths = 0;" to line 1

Works perfectly ;) thx GirlFlash yay :shake:
a2z
Newcomer
 
Posts: 3
Joined: Thu Jul 09, 2009 12:03 pm

Re: My custom code is not working HELP ME!

Postby SophieH » Sat Oct 17, 2009 9:55 am

no worries, I'm glad I could help :)
User avatar
SophieH
Site Admin
 
Posts: 76
Joined: Fri Aug 08, 2008 8:01 pm
Location: UK - Europe

Re: My custom code is not working HELP ME!

Postby tiffanyyu » Fri Jun 18, 2010 9:41 am

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
tiffanyyu
Newcomer
 
Posts: 1
Joined: Fri Jun 18, 2010 5:31 am


Return to Edward Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron