8 Replies Latest reply on Aug 19, 2010 10:25 AM by Ned Murphy

# Counter AS2

I am making a puzzle game. I have finished everything but points counter. I was thinking I would use how many times the user clicks the reset button as the score, the counter starts at a number say, 50, and every time the user clicks the reset button, they lose a point. I just don't know how to code this, or if it is possible (surely, it must be possible). Help is sincerely appreciated.

Thanks,

universal_binary

• ###### 1. Re: Counter AS2

Create a score variable and have your reset button's actions subtract 1 from that variable.  How do you code the reset button now?

• ###### 2. Re: Counter AS2

the counter works but it counts like this:

50

4

4

4

4

45

44

43

42

41

40

3

3

3

3

35

34

33

32

.

.

.

here is the code for the counter (the counter is named "points"):

on frame of counter:

points = 50;

on button:

on (release) {

points -= 1;

}

Also, do negative numbers work or will it just count up again?

If it just counts up again is there a way to make it stop at 0 and not change?

• ###### 3. Re: Counter AS2

The button code looks okay, though you should avoid using the approach of placing code on objects (give them instance names and place the code in the timeline).  What becomes suspect is when you say the points is in the frame of the counter.  The points should be defined in frame 1 on their own layer using...

var points = 50;

and hopefully you either stay in frame 1 all the time or you never return there if you leave it while running the file.  That layer should extend the full length of the populated timeline so that points is accessible anywhere along the timeline.

THe next question is.... what does the counter do with the points value?

• ###### 4. Re: Counter AS2

The points value is defined in frame 1of its own layer.

the points is displayed in a dynamic text box.

the code on the first frame is

var points = 50;

and button code is:

on (release) {

points -= 1;

}

it is still leaving out the last digit if it is 0, 9, 8, 7, or 6.

• ###### 5. Re: Counter AS2

Try making the textfield a little bigger and see if that helps at all.  You can check the true value if you trace it in the button code...

on (release) {

points -= 1;

trace(points);

}

• ###### 6. Re: Counter AS2

I made the textfield much bigger and it didn't fix the problem. When I put

on (release) {

points -= 1;

trace(points);

}

as the code the output messages showed that it was the digits of 0, 9, 8, 7, and 6 that werent displayed. all other numbers were displayed by the texfield. the textfield also has a problem with the "-" sign.

• ###### 7. Re: Counter AS2

I can't make sense of what you tried to explain regarding the output.

• ###### 8. Re: Counter AS2

Accually, it started working. I just had to change the font size.