Events

Keyboard events

on_key_down

Token.on_key_down(key)[source]

on_key_down is called one time when a key is pressed down.

Instead of on_key_down you can use on_key_down_letter, e.g. on_key_down_a or on_key_down_w , if you want to handle a on_key_down event for a specific letter.

Examples:

Register a key_down event:

token1 = miniworldmaker.Token(position = (2, 2) )
token1.add_costume((100,0,100,100))

@token1.register
def on_key_down(self, key):
    print(key)

Register on_key_down_a event

token1 = miniworldmaker.Token(position = (2, 2) )
token1.add_costume((100,0,100,100))

@token1.register
def on_key_down_a(self):
    print("a")
Parameters

key (list) – The typed key as list (e.g. [‘A’, ‘a’]) containing both uppercase and lowercase of typed letter.

Raises

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

on_key_pressed

Token.on_key_pressed(key)[source]

on_key_pressed is called when while key is pressed. If you hold the key, on_key_pressed is repeatedly called again and again until the key is released.

Like on_key_down the method can be called in the variant on_key_pressed_[letter] (e.g. on_key_pressed_w(self)).

Examples

Register on_key_pressed event:

token1 = miniworldmaker.Token(position = (2, 2) )
token1.add_costume((100,0,100,100))

@token1.register
def on_key_pressed(self, key):
    print("pressed", key)

@token1.register
def on_key_pressed_s(self):
    print("pressed s")
Parameters

key (list) – The typed key as list (e.g. [‘C’, ‘c’, ‘D’, ‘d’]) containing both uppercase and lowercase of typed letter.

Raises

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

Mouse events

on_mouse_left

Token.on_mouse_left(position)[source]

Method is called when left mouse button was pressed.

Examples

Register mouse event to board

@board.register
def on_mouse_left(self, position):
    print("left" + str(position))

@board.register
def on_mouse_right(self, position):
    print("right" + str(position))

@board.register
def on_mouse_middle(self, position):
    print("middle" + str(position))
Parameters

position (tuple) – Actual mouse position as tuple (x,y)

Raises

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

on_mouse_right

Token.on_mouse_right(position)[source]

on_mouse_right is called when right mouse button was pressed.

Examples

Register mouse event to board

@board.register
def on_mouse_right(self, position):
    print("right" + str(position))
Parameters

position (tuple) – Actual mouse position as tuple (x,y)

Raises

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

on_mouse_motion

Token.on_mouse_motion(position)[source]

on_mouse_motion is called when right mouse moves.

Examples

Register mouse-motion event to board

@board.register
def on_mouse_motion(self, position):
    print("motion" + str(position))
Parameters

position (tuple) – Actual mouse position as tuple (x,y)

Raises

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

on_clicked_left

Token.on_clicked_left(position)[source]

The mouse is on top of a token and mouse was clicked.

Examples

Registering a on_click event:

token = miniworldmaker.Token((2,2))

@token.register
def on_clicked_left(self, position):
    print("clicked" + str(position))
Parameters

position (tuple) – Actual mouse position as tuple (x,y)

Raises

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

on_clicked_right

Token.on_clicked_right(position)[source]

The mouse is on top of a token and mouse was clicked.

Examples

Registering a on_click event:

token = miniworldmaker.Token((2,2))

@token.register
def on_clicked_right(self, position):
    print("clicked" + str(position))
Parameters

position (tuple) – Actual mouse position as tuple (x,y)

Raises

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

Messages

Token.on_message(message)[source]

Messages are used to allow objects to communicate with each other.

Send a message:

  • A token and the board can send a message to all tokens and the board with the command: self.send_message(“message_string”)

Process a message:

  • If your board or your token should react to messages you can use the event on_message:

Examples

Receive a message

@player.register
def on_message(self, message):
    if message == "Example message":
    do_something()
Parameters

message (str) – The message as string

Raises

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