4 Replies - 36212 Views - Last Post: 16 February 2009 - 01:24 PM

#1 tkdoherty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-February 09

Flash Score Counter

Posted 11 February 2009 - 12:40 PM

I'm an actionscript neophyte and am working on a very simple basketball game. Most of the gameplay is controlled by simply clicking buttons and jumping to various points on the main timeline. After reading a post on this board I added a simple score counter to the game. To start the counter, I added a dynamic text field with the instance name "scorecounter" and the following actionscript:

var score = 0;
scorecounter.text = score;

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


Each time the user clicks on the right spot on the screen, the counter increases:

on (press) {
	updateScore();
}


However, since this is a basketball game, I want the counter to increase by 2 for each basket made. I tried the following actionscript:

var score = 0;
scorecounter.text = score;

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


But this causes the counter to stay on the number 2. I'm sure there must be a simple fix but, newbie that I am, I'm not sure how the syntax should go.

Also, I would like to find a way to display the high scores after a user has finished playing (and if possible allow the user to enter their initials). The game will be a Flash exe file, so I realize that the high scores will be wiped out when the game is closed. That's okay, but is there a way to show a highscore list when the game is open but not being played?

Thanks for the help!

Is This A Good Question/Topic? 0
  • +

Replies To: Flash Score Counter

#2 skater_00   User is offline

  • D.I.C Regular
  • member icon

Reputation: 12
  • View blog
  • Posts: 256
  • Joined: 30-April 08

Re: Flash Score Counter

Posted 11 February 2009 - 03:54 PM

I "recreated" your counter in AS3 and got it to count correctly.

var score:uint;

function init():void
{
	score = 0;
	scorecounter.text = score.toString();
	clip.buttonMode = true;
	clip.addEventListener(MouseEvent.CLICK, on_press);
}

function on_press(event:MouseEvent):void
{
	updateScore();
}

function updateScore():void
{
	score += 2;
     scorecounter.text = score.toString();
}

init();


Hope you can use this to debug where necessary..
Was This Post Helpful? 0
  • +
  • -

#3 tkdoherty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-February 09

Re: Flash Score Counter

Posted 12 February 2009 - 09:15 AM

Thanks Skater. After looking at your suggestion, I was able to adjust my code as follows:


var score = 0;
scorecounter.text = score;

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

Was This Post Helpful? 0
  • +
  • -

#4 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1635
  • View blog
  • Posts: 8,497
  • Joined: 07-September 06

Re: Flash Score Counter

Posted 12 February 2009 - 02:12 PM

Are you trying to add 2 points to the score?

	 score += 1;
	 scorecounter.text = ++score;


Does just that, you only need to use:

score += 1;


or

++score;


Putting both increments the score by 2.
Was This Post Helpful? 0
  • +
  • -

#5 tkdoherty   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-February 09

Re: Flash Score Counter

Posted 16 February 2009 - 01:24 PM

Yes -it is a basketball game so I want the score to increment by 2.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1