Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to add scoring to my game

New Here ,
Nov 11, 2013 Nov 11, 2013

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!

TOPICS
ActionScript
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 11, 2013 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2013 Nov 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2013 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2013 Nov 12, 2013

I created a 'dynamic text' and named its instance name "score".

I then added the coding that you gave me onto the action script, however, it still didnt work.

Im using action script 3.

What am I doing wrong?

Thank you for helping and being so patient!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2013 Nov 12, 2013

That's because the textfield is not a numeric variable, so you cannot assign a value to it using the code I showed.  To show the score in the textfield you need to assign the score value to the 'text' property of the textfield.  So change the name of the textfield and assign the value of the score to it just after you update the score... something like...

   score++;

   scoreTxt.text = String(score)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2013 Nov 12, 2013

I've tried that and it still doesnt work. I'm sure its probably something I'm doing wrong.

var score:int=0;

higher_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_33);

function fl_ClickToGoToAndStopAtFrame_33(event:MouseEvent):void

{

          score+1;

          scoretxt.text=string(score)

           

          gotoAndStop(84);

}

lower_2.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_70);

function fl_ClickToGoToAndStopAtFrame_70(event:MouseEvent):void

{

             

          gotoAndStop(64);

          }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2013 Nov 12, 2013

YOu didn't use the code I showed.  What you wrote it not the way to increment a value....   score+1;

Here are three ways to add 1 to the score...

score++;

score += 1;

score = score + 1;

You also didn't use what I showed for the textfield...  case matters

scoretxt.text=String(score);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2013 Nov 12, 2013

Thanks for all your help.

When I test it, it just runs through all of my frames. This only happens having input the extra coding.

It says the error is "Access of undefined property scoretxt"

How do I define it?

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 12, 2013 Nov 12, 2013

You assign that as the instance name of the Textfield.  Go back thru everything I have offered and try to follow it more closely.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2013 Nov 13, 2013

Thanks, I've now managed to do it on that frame!

I need to apply that coding to other frames too. Do I need to adjust any of it when doing so, as when I input the same thing, a error comes up saying;

"A conflict exists with definition score in namespace internal."

Alternitively, if I add the coding on its own layer in actions, how do i get it to work across a number of frames? For instance frames 63 through to 81.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 13, 2013 Nov 13, 2013

You only want to declare the variable in frame 1 as I said in my initial instructions.

Rightfully you should only need to define the buttons and the functions once in frame 1 as well, using a variable for the correct and incorrect frame numbers.  Then as you move along the timeline you just change that values of the variables without having to rewrite the functions all the time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 13, 2013 Nov 13, 2013

Thank you for all your help and for bein so patient!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 13, 2013 Nov 13, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines