Sensors

With sensors, tokens can sense their environment.

Listeners

Register any of these listener methods, to catch a sensor-event:

sensing_on_board

Token.on_sensing_on_board()[source]

on_sensing_on_board is called, when token is on board”

Examples

Register on_sensing_on_board method:

@player.register
    def on_sensing_on_board(self):
    print("Player 3: I'm on the board:")
Raises

NotImplementedOrRegisteredError – The error is raised when method is not overwritten or registered.

sensing_not_on_board

Token.on_sensing_not_on_board()[source]

on_sensing_not_on_board is called, when token is not on board”

Examples

Register on_sensing_not_on_board method:

@player.register
    def on_sensing_not_on_board(self):
    print("Warning: I'm not on the board!!!")
Raises

NotImplementedOrRegisteredError – The error is raised when method is not overwritten or registered.

sensing_borders

Token.on_sensing_borders(str)[source]

on_sensing_border is called, when token is near a border

Parameters

str (List) – A list of strings with found borders, e.g.: [‘left’, ‘top’]

Examples

Register on_sensing_border_event:

@player.register
def on_sensing_borders(self, borders):
    print("Player 4: Sensing borders:")
    print("Borders are here!", str(borders))
Raises

NotImplementedOrRegisteredError – The error is raised when method is not overwritten or registered.

token

Token.on_sensing_token(token)[source]

on_sensing_token is called, when token is sensing a token on same position

Parameters

token (Token) – The found token

Examples

Register sensing_token event

@player.register
def on_sensing_token(self, token):
    print("Player 1: Sensing token:")
    if token == player2:
    print("Am i sensing player2?" + str(token == player2))
Raises

NotImplementedOrRegisteredError – The error is raised when method is not overwritten or registered.

Active Sensors

sensing_token

Token.sensing_token(token_filter=None, distance=0, collision_type='default')[source]

Senses if tokens are on tokens position. Returns the first found token.

../_images/sensing_token.png
Parameters
  • token_filter – filter by token type or by token instance

  • distance – Specifies the distance in front of the actuator to which the sensor reacts.

  • collision_type – The type of collision which should be checked:

Returns

First token found by Sensor

Examples

Sensing a fireplace in rpg.py:

>>>  fireplace =  self.player.sensing_token(Fireplace)
>>>    if fireplace:
>>>      self.console.newline("Du zündest die Feuerstelle an.")
>>>      self.fireplace.burn()
Return type

List[Token]

sensing_tokens

Token.sensing_tokens(token_filter=None, distance=0, collision_type='default')[source]

Senses if tokens are on tokens position. Returns a list of tokens.

../_images/sensing_tokens.png
Parameters
  • token_filter – filter by token type. Enter a class_name of tokens to look for here

  • distance – Specifies the distance in front of the actuator to which the sensor reacts.

  • collision_type – The type of collision which should be checked:

Returns

All tokens found by Sensor

Return type

List[Token]

sensing_borders

Token.sensing_borders(distance=0)[source]

Senses borders

../_images/sensing_borders.png
Parameters

distance – Specifies the distance in front of the actuator to which the sensor reacts.

Returns

True if border was found.

Return type

bool

sensing specific border

  • sensing_left_border(distance),

  • sensing_right_border(distance),

  • sensing_top_border(distance),

  • sensing_bottom_border(distance)

    Returns True if token is sensing the border (when moving distance steps forward)

sensing_colors

Token.sensing_colors(colors, distance)[source]

Senses colors in board-background at token-position

Parameters
  • colors

  • distance – Specifies the distance in front of the actuator to which the sensor reacts.

Returns: All colors found by Sensor

Return type

tuple

sensing_point

Token.sensing_point(board_position)[source]

Is the token colliding with a specific (global) point?

Returns: True if point is below token