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

Adding a score collision

New Here ,
Dec 05, 2018 Dec 05, 2018

So, this is my code.

```````````

import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY_DOWN,moveClip);

function moveClip(event:KeyboardEvent):void

{

  if(event.keyCode == 40)

  {

  mcSquare1.y += 10;

  }

}

stage.addEventListener(KeyboardEvent.KEY_UP,moveClip2);

function moveClip2(event:KeyboardEvent):void

{

  if(event.keyCode == 38)

  {

  mcSquare1.y -= 10;

  }

}

stage.addEventListener(KeyboardEvent.KEY_UP,moveClip3);

function moveClip3(event:KeyboardEvent):void

{

  if(event.keyCode == 37)

  {

  mcSquare1.x -= 10;

  }

}

stage.addEventListener(KeyboardEvent.KEY_UP,moveClip4);

function moveClip4(event:KeyboardEvent):void

{

  if(event.keyCode == 39)

  {

  mcSquare1.x += 10;

  }

}

stage.addEventListener(KeyboardEvent.KEY_UP,moveClip5);

function moveClip5(event:KeyboardEvent):void

{

  if(event.keyCode == 16)

  {

  mcSquare1.rotation += 315;

  }

}

var mcScore == 0;

if (mcSquare1.hitTest(mcFinish)){

  var mcScore += 1;

}

```````````

It does not work, and gives me the errors

Scene 1, Layer 'actions', Frame 1, Line 50, Column 131086: Syntax error: expecting semicolon before equals.
Scene 1, Layer 'actions', Frame 1, Line 52, Column 141086: Syntax error: expecting semicolon before plusassign.

Everything works until the last part, adding the score, is added.

When said part, is added everything goes to shit.

thanks

245
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

correct answers 1 Correct answer

LEGEND , Dec 05, 2018 Dec 05, 2018

hunterm28452256  wrote

var mcScore == 0;

if (mcSquare1.hitTest(mcFinish)){

  var mcScore += 1;

}

The double-equals operator is used for comparison, not assignment, and you're trying to declare a variable twice.

Also, you can use just ++ instead of += 1.

Translate
LEGEND ,
Dec 05, 2018 Dec 05, 2018

hunterm28452256  wrote

var mcScore == 0;

if (mcSquare1.hitTest(mcFinish)){

  var mcScore += 1;

}

The double-equals operator is used for comparison, not assignment, and you're trying to declare a variable twice.

Also, you can use just ++ instead of += 1.

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
Community Expert ,
Dec 05, 2018 Dec 05, 2018
LATEST

double equal (==) is for testing equality.  use a single equal (=) for assignment.  and don't use 'var' twice and do type your variables:

var mcScore:int=0;

if(...){

mcScore++;

}

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