4 Replies - 2410 Views - Last Post: 25 March 2010 - 01:09 PM

#1 ILIKECPP   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 14-October 08

Score Counter stuck on 0

Posted 21 March 2010 - 12:31 PM

I'm using this code that I found through searching the forums:
var score = 0;
scorecounter.text = score;

function updateScore() {
     scorecounter.text = ++score;
}


and on another layer in that same frame I have a movie clip ("dot") with this code in it:
onClipEvent (enterFrame) {
/* some irrelevant code, then this instance where I call "updateScore" */
	if(this.hitTest(_root.pacman)) {
		this._alpha=0;
		updateScore();
	}



The problem is, the dynamic textbox with the instance name "scorecounter" and variable "scorecounter" just stays on 0. I think it may have something to do with where I'm calling the functions within clipEvents or possibly where I placed the "var score = 0" but I cant figure it out... any help?

This post has been edited by ILIKECPP: 21 March 2010 - 12:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Score Counter stuck on 0

#2 jason-pc   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 61
  • Joined: 10-January 09

Re: Score Counter stuck on 0

Posted 21 March 2010 - 01:19 PM

View PostILIKECPP, on 21 March 2010 - 11:31 AM, said:

I'm using this code that I found through searching the forums:
var score = 0;
scorecounter.text = score;

function updateScore() {
     scorecounter.text = ++score;
}


and on another layer in that same frame I have a movie clip ("dot") with this code in it:
onClipEvent (enterFrame) {
/* some irrelevant code, then this instance where I call "updateScore" */
	if(this.hitTest(_root.pacman)) {
		this._alpha=0;
		updateScore();
	}



The problem is, the dynamic textbox with the instance name "scorecounter" and variable "scorecounter" just stays on 0. I think it may have something to do with where I'm calling the functions within clipEvents or possibly where I placed the "var score = 0" but I cant figure it out... any help?



i do not know much about ActionScript but can i suggest changing the following line...

scorecounter.text = ++score;



to this
scorecounter.text =++score;



not sure if the operator =++ can have spaces in it or not, but worth a try.
Was This Post Helpful? 0
  • +
  • -

#3 jdouglas   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 9
  • Joined: 04-January 10

Re: Score Counter stuck on 0

Posted 22 March 2010 - 12:28 PM

I would suggest putting a breakpoint in the updateScore() function, to make sure it is getting called. I would also try casting score to a string before assigning it to scorecounter.text, just in case that is a problem.

scorecounter.text = String(++score);
Was This Post Helpful? 0
  • +
  • -

#4 Aurel300   User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: Score Counter stuck on 0

Posted 24 March 2010 - 08:30 AM

scorecounter.text = ++score;
That is perfectly valid.

Put this:
trace("Yes it is being called.");

just before the increment score part.

Then, do something that SHOULD increase the score. Close the test movie, and check output - if there is "Yes it is being called." it SHOULD work...
If not, the score increment is not even being called.

One last thing - I noticed you put "this.hittest(_root.pacman)" in the condition...
If "this" is contained in a MovieClip or something, it will never work - both test subjects must be in the same timeline level.

This post has been edited by Aurel300: 24 March 2010 - 08:31 AM

Was This Post Helpful? 0
  • +
  • -

#5 ILIKECPP   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 14-October 08

Re: Score Counter stuck on 0

Posted 25 March 2010 - 01:09 PM

The hittest code IS in a movie clip like you said, but the rest of the code in that hittest area (changing alpha to 0) works. Also the trace did work, I got an output.

Anything else I could do to make this work? The two objects hitting each other are separate movie clips, but it seems to be only the updateScore() that isn't working.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1