7. events

There are several important methods that you can fill with content:

7.1. Special Event Methods

7.1.1. The act() method

The Act method is called again and again at short intervals. Here you can place code that should be executed over and over again, e.g:

    def act(self):
        if not self.look_on_board(direction = "forward"):

The Actor looks one square forward and checks whether it is still on the playing field. If so, he moves one square forward. Otherwise he turns 90° to the left.

7.1.2. Sensing methods

Each time an actor detects something different, its corresponding sensing methods are called:

on_sensing_tokens(token_list): Tracks all tokens at the same location. on_sensing_borders(borders): Returns a list of borders that are currently touched (e.g. [“right”, “top”]). on_sensing_on_board(): Called when the player is on the field. on_sensing_not_on_board(): Called when the player is not on the field.

7.2. General event handling with the get_event method

7.2.1. The get_event(event, data) method

The get_event(event, data) method) is used to react to events of various kinds.

  • The parameter event always contains a string with the event, for example:

    • mouse-left”: The left mouse button was pressed.

  • The data parameter contains information that matches the event.

    • mouse-left”, “mouse-right” : The tile on the board that was clicked. Example:

    def get_event(self, event, data):
        if event == "key_down":
            if "W" in data:
            elif "S" in data:
            elif "A" in data:
            elif "D" in data:

The code checks whether the event “key_down” was thrown. The parameter data returns a list with all buttons pressed at this moment. It can therefore be checked: *If the button X was pressed, do …

Translated with www.DeepL.com/Translator