PDA

View Full Version : displaying a counter



joobny
March 1st, 2010, 12:22 PM
I've been posting a lot of questions up recently and I've been getting some great help so thanks everybody!

I'm in the process of trying to work out how a scoring system will work in the game that I'm developing.

I've added
var counter:int = 0; at the beginning of my code, and when the player mouses over objects to destroy them the killObject function includes the line
counter ++;

The bit I'm struggling with is displaying this number in a dynamic text box. I've had a search around but can't seem to find what I'm looking for.

All of the gameplay code is written in one frame of the main timeline and it begins after a short introduction animation. When the gameplay is over the AS3 code will instruct the movie to move on to the next frame of the timeline so that an outro animation can be played. The player's final score will be displayed at this point.

I'm sure this is fairly straight forward but I can't find out how to do it...

Thanks again for all your help!

BoppreH
March 1st, 2010, 12:39 PM
Well, if you already have the dynamic text box, just give it an instance name and use this to set the text:

textFieldName.text = String(counter)

joobny
March 1st, 2010, 12:54 PM
Okay, I amended it so it looks like this:


var counter:int = 0;
scoreCounter.text = String(counter);

It's displayed on the screen but the number stays at 0 and does not increase by 1 when the killObject function says "counter ++" like intended.

Thanks!

BoppreH
March 1st, 2010, 03:20 PM
Okay, I amended it so it looks like this:


var counter:int = 0;
scoreCounter.text = String(counter);

It's displayed on the screen but the number stays at 0 and does not increase by 1 when the killObject function says "counter ++" like intended.

Thanks!

The problem is that the value is set only once, when the counter is 0. You must update the text at every increase.

So, just use the same line right after increasing the counter.