Skip to main content
hunterm28452256
Participant
December 5, 2018
Answered

Adding a score collision

  • December 5, 2018
  • 2 replies
  • 272 views

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

    This topic has been closed for replies.
    Correct answer ClayUUID

    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.

    2 replies

    kglad
    Community Expert
    Community Expert
    December 5, 2018

    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++;

    }

    ClayUUIDCorrect answer
    Legend
    December 5, 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.