# Trying to make scoring for my game work but having trouble

**URL:** <https://forum.kirupa.com/t/trying-to-make-scoring-for-my-game-work-but-having-trouble/327832>\
**Category:** flash\
**Created:** [March 30, 2012, 6:07pm UTC](https://forum.kirupa.com/t/trying-to-make-scoring-for-my-game-work-but-having-trouble/327832 "2012-03-30T18:07:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaymsWisdom](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@JaymsWisdom](https://forum.kirupa.com/u/JaymsWisdom)\
**Post date:** [March 30, 2012, 6:07pm UTC](https://forum.kirupa.com/t/trying-to-make-scoring-for-my-game-work-but-having-trouble/327832/1 "2012-03-30T18:07:36Z")

</div>

Hiya guys

I’m trying to add a scoring element to the game I have been teaching a bunch of kids to make over the last few weeks. I’ve created a variable called score which is set to 0 and a second variable that is equal to score. The idea is that when the player hits a red block it gives them 10 points. I can make the score increase by 10 by then it stops there and doesn’t increase when you hit other blocks. I’m pretty sure I’m missing something that i logically need but I can’t quite see it. Any help would be greatly appreciated.

```auto
//add the event listener to listen when a key is pressedstage.addEventListener(KeyboardEvent.KEY_DOWN, CharacterMove);

//variables added for the score
var score:Number=0+scoreCount;
var scoreCount=0;

//add the function to tell the object which direction to move and how far
function CharacterMove(event:KeyboardEvent):void {
	switch (event.keyCode) {
	case Keyboard.UP :
	MainCharacter.y-=10;
	break;
	case Keyboard.DOWN :
	MainCharacter.y+=10;
	break;
	}
//controls the boundaries of the stage	
	if (MainCharacter.y<0) {        
       MainCharacter.y=0;    
   	}    
   	else if (MainCharacter.y > 400-73) {
       MainCharacter.y=400-73; //height of the stage minus the hieght of the character
   	}		
}

//add the event listener to listen when a collision is detected
MainCharacter.addEventListener(Event.ENTER_FRAME, checkCollision);

//add the function to check if the objects collide
function checkCollision(event:Event) {
	
	//test the mainCharacter to see if it overlaps a block
	if (MainCharacter.hitTestObject(BlueBlock)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock2)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock3)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock4)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock5)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock6)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock7)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(BlueBlock8)) {
		gotoAndPlay("end");
	}
	if (MainCharacter.hitTestObject(RedBlock1)) {
		messageText.text = score +(scoreCount+10);
	}
	if (MainCharacter.hitTestObject(RedBlock2)) {
		messageText.text = score +(scoreCount+10);
	}
}

```

Cheers guys. I know the code is not particularly well written and could be done much more professionally but the idea is that I teach the kids a new thing to add each week and this is the way it works.
