Rotation by 45 degrees each time

I would like to be able to rotate a movieclip by 45 degrees each time i press left or right.

I have got this


on (keyPress "<Right>") {
 _rotation=+45
}
on (keyPress "<Left>") {
 _rotation=-45
}

However, this moves the movie clip to the point of 45 degrees or minus 45 degrees depending on the key pressed.

I would like to add +45 to the rotation when i press the right key and -45 when i press the left key.

What have i done wrong. Please can you help me?

+=
-=

on (keyPress "<Right>") {
 _rotation +=45
}
on (keyPress "<Left>") {
 _rotation-=45
}

note tha you have placed + & = in the wrong way

Just so i fully understand.

= 45 means rotate to 45 degrees.

+= 45 Means add 45 degrees to the current rotation.
-= 45 means minus 45 degrees to the current rotation.

Yes, ‘=’ will set a value, ‘+=’ will increase by value and ‘-=’ will decrease by value.

Just as another option (less efficient) you could also have used
rotation = rotation+45;
that’s the long hand for the += operator.

There are two more shorthand operators like this, the decrementation operator and incrementation operator
variable–; //subtracts one from the variable
vairable++; //adds one to the variable