Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables not incrementing or displaying properly

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
I'm really pulling my hair out with this one.

Code:
	if (hitTest("_root.player.hit")) {
		_root.pointsSave+=5;
		trace(_root.pointsSave);
		this.removeMovieClip();
    }

This should at least trace 5,10,15,20,25,30....

But it outputs 5,5,5,5,5,5,5....

Any idea as to why?

frozenpeas
 
Another thing I tried is
Code:
_root.pointsSave++;
and it outputs 1,1,1,1,1,1... never incrementing the variable.

frozenpeas
 
I can't really replicate your hitTest bit...
But this works for me...

this.onEnterFrame = function(){
_root.pointsSave+=5;
trace(_root.pointsSave);
}

What happens if you remove your removeClip bit?

if (hitTest("_root.player.hit")) {
_root.pointsSave+=5;
trace(_root.pointsSave);
//this.removeMovieClip();
}


 
^ commenting out that line doesn't fix it.

frozenpeas
 
Did you set your initial value for pointsSave?

if (_root.pointsSave == null){
_root.pointsSave = 0;
}

if (hitTest("_root.player.hit")) {
_root.pointsSave+=5;
trace(_root.pointsSave);
this.removeMovieClip();
}


Wow JT that almost looked like you knew what you were doing!
 
also notice that _root.player.hit is in quotes.

Shouldn't it be:

if (hitTest(_root.player.hit)){
_root.pointsSave+=5;
trace(_root.pointsSave);
this.removeMovieClip();
}

???

Wow JT that almost looked like you knew what you were doing!
 
pixl8r,

_root.player.hit needs to be in quotes. If the hitTest didn't work, the trace wouldn't be called at all.

And pointsSave has been declared as a variable elsewhere, but it actually doesn't matter because it would be declared as I add 5 to it anyway.

Thanks for the feedback.

frozenpeas
 
Fixed.

I had made an error that was causing the variable to be reset to zero earlier in the script.

Thanks for your help, folks. Have a good day.

frozenpeas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top