# Directions¶

## Token direction¶

property Token.direction: int

Directions are handled exactly as in the Scratch programming language, see: Scratch Wiki

The default direction is 0°. All tokens are looking “up”

Values for Direction

• 0° or “up”: up

• 90° or “right”: Move right

• -90° or “left”: Move left

• 180° or “down”: Move down

• “forward”: Current direction

Sets direction of the token.

You can use a integer or a string to describe the direction

Options
• 0, “up” - Look up

• 90, “right”, - Look right

• -90, “left”, - Look left

• -180, 180, “down” - Look down

Examples

Move in a direction with WASD-Keys

```>>> def on_key_down(self, keys):
>>>    if "W" in keys:
>>>      self.direction = "up"
>>>    elif "S" in keys:
>>>      self.direction = "down"
>>>    elif "A" in keys:
>>>      self.direction = "left"
>>>    elif "D" in keys:
>>>      self.direction = "right"
>>>    self.move()
```
Return type

`int`

## point_in_direction¶

Sets direction of token:

Token.point_in_direction(direction)[source]

Token points in given direction.

You can use a integer or a string to describe the direction

Parameters

string (The direction as integer or) –

Options
• 0, “up” - Look up

• 90, “right”, - Look right

• -90, “left”, - Look left

• -180, 180, “down” - Look down

Examples

Move in a direction with WASD-Keys

```>>> def on_key_down(self, keys):
>>>    if "W" in keys:
>>>      self.direction = "up"
>>>    elif "S" in keys:
>>>      self.direction = "down"
>>>    elif "A" in keys:
>>>      self.direction = "left"
>>>    elif "D" in keys:
>>>      self.direction = "right"
>>>    self.move()
```
Return type

`int`

## turn_left¶

Turns token left by degrees degrees

Token.turn_left(degrees=90)[source]

Turns actor by degrees degrees left

Options:
• You can set the value token.is_rotatable = False if you don’t want the token to be rotated.

Parameters

degrees – degrees in left direction

Returns

New direction

Return type

`int`

## turn_right¶

Turns token right by degrees degrees

Token.turn_right(degrees=90)[source]

Turns token by degrees degrees right

Options:
• You can set the value token.is_rotatable = False if you don’t want the token to be rotated.

Parameters

degrees – degrees in left direction

Returns

New direction

## flip_x¶

Mirrors the Token over x-Axis

Token.flip_x()[source]

Flips the actor by 180° degrees

Returns

The new direction

Return type

int

Examples

flip a token.

```>>>  def on_sensing_not_on_board(self):
>>>    self.move_back()
>>>    self.flip_x()
```
Return type

`int`