Events are a central concept of the Miniworldmaker:

  • Events can be used to retrieve input (e.g. mouse clicks or keyboard input).

  • With events objects can communicate with each other (e.g. via messages).

Register an event

For the board or a player to respond to an event, it must be registered.

This works in the same way as the act() method:

This registers the on_key_down_w method, which checks whether the w key has been pressed.

As soon as the key is pressed, the token player moves one step forward.

As before, each registered method takes the keyword self as its first parameter, and you can use this keyword to access attributes and methods of the object within the method.

on_key_down and on_key_pressed

There are two functions on_key_down(self, key) and on_key_pressed(self, key):

  • The on_key_down function is called exactly once when the key is pressed.

  • The function on_key_pressed, on the other hand, is called again and again as long as the key is pressed.

… note::

Both functions exist in the variant on_key_down_b(self) / on_key_pressed_c(self) to query the pressing of a concrete key as well as in the variant on_key_down(self, key) / on_key_pressed(self, key) to process all keyboard queries.

Send messages

Use send message(self, message) to send a global message to all objects and the board. These messages can be processed with on_message.