6. Sensing

6.1. Active tracking

An actor can track down whether he is at his position or before other actors and so on.

This can be done with the following function, for example:

actor.sensing_tokens(distance, token)

The function detects whether there are actors at the current position of the actor (or distance steps forward). If so, they are returned as a list, otherwise None is returned.

6.1.1. Example

The example checks whether the actor is standing in front of a locked door:

actors_in_front = self.sensing_tokens(distance = 1, token = door)
        if self.board.door in actors_in_front:
            if self.board.door.closed:
                message = "The Door is closes"

6.2. Sensing via event methods

Alternatively, you can also implement event methods: The on_sensing_xy method is called every time an actor detects something.

–> see also events

6.2.1. Functions to find objects

6.2.1.1. Sensing Tokens

Tracks tokens

...autoclass:: miniworldmaker.tokens.token.Token.Token
   :members: sensing_tokens
   :noindex:

6.2.1.2. Sensing Token

Tracks a single token. The method is more efficient than sensing_tokens

...autoclass:: miniworldmaker.tokens.token.Token.Token
   :members: sensing_token
   :noindex:

6.2.1.3. Sensing Border

Checks if there’s an edge nearby.

...autoclass:: miniworldmaker.tokens.token.Token.Token
   :members: sensing_borders
   :noindex:

6.2.1.4. Sensing Border

Checks if the position is on the playing field.

...autoclass:: miniworldmaker.tokens.token.Token.Token
   :members: sensing_on_board
   :noindex:

6.2.1.5. Sensing Color

Checks the color under the actor (related to the background of the game world)

...autoclass:: miniworldmaker.tokens.token.Token.Token
   :members: sensing_on_board
   :noindex:

Translated with www.DeepL.com/Translator