Skip to main content
Participating Frequently
November 11, 2013
Question

How to add scoring to my game

  • November 11, 2013
  • 1 reply
  • 1991 views

I have made a simple card game on flash in the style of the game Higer or Lower. So far, when the player clicks the buttons 'Higher' or 'Lower', it tells them if they are correct of incorrect. I now want to have their score add up as they play the game.

Im new to Flash and have probably gone about the long way of creating this game but I within my timeline, i have a number of keyframes that the player is directed to if they get the answer correct, and then a number of keyframes with identical images if the player is incorrect. These all link up, and plays smoothly if the player is correct or incorrect etc.

Frames 63-81 are the pages the player lands on if they get the answer correct.

I need some simple coding that effectively says "if player lands on frame 64, add one point" for example.

Please help!

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 11, 2013

You say that the user is directed to certain frames depending on whether or not they are correct. That decision process should be all you need to be able to add/subtract to a score variable.

Participating Frequently
November 12, 2013

I thought it'd be something like that, i just don't know what to write in the coding.

In Actions, each frame looks like this:

higher_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_33);

function fl_ClickToGoToAndStopAtFrame_33(event:MouseEvent):void

{

          gotoAndStop(84);

}

lower_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_70);

function fl_ClickToGoToAndStopAtFrame_70(event:MouseEvent):void

{

          gotoAndStop(64);

}

Where and what would I need to write in order to create my score?

Like I said, I'm very new to this, so it'd be great if you could help!

Ned Murphy
Legend
November 12, 2013

In the first frame you would declare a variable for keeping the score.  Let's say you name it "score"....

var score:int = 0;

With the way you show the code now, if one of those is a correct and the other is not then you just add in a line to each before you change frames that increments/decrements the score variable... as in...

function fl_ClickToGoToAndStopAtFrame_33(event:MouseEvent):void

{

          score++;

          gotoAndStop(84);

}

function fl_ClickToGoToAndStopAtFrame_70(event:MouseEvent):void

{

          score--;

          gotoAndStop(64);

}

The way you show doing this it is likely you can streamline the code such that you do not have new functions for every button, and you even only ever have two buttons instead of new ones for each guess.