Solarus quests  1.6
Quest maker's reference
Block

Blocks are solid map entities that may be pushed or pulled by the hero.

This type of map entity can be declared in the map data file. It can also be created dynamically with map:create_block().

Overview

Blocks that can move may be pushable, pullable or both pushable and pullable. A block can optionally be moved a limited number of times. It can be moved either to any direction (the four main directions) or to a specific direction only.

The size of a block is by default 16x16 pixels (the default size of the hero), but as always, its sprite may be larger.

Blocks are normally always moved by steps of 16 pixels. Thus, they can stay aligned on the 8x8 grid of the map. However, they may get stopped in the middle of their movement if they collide with entities like enemies or non-playing characters. In this case, they lose their alignment on the grid, and this might be a problem when want the to move a block precisely through narrow places and place it at an exact position to solve a puzzle. To deal with this potential issue, the engine automatically realigns the block to the 8x8 grid the next time it is moved.

Methods inherited from map entity

Blocks are particular map entities. Therefore, they inherit all methods from the type map entity.

See Methods of all entity types to know these methods.

Methods of the type block

The following methods are specific to blocks.

block:reset()

Restores the block at its initial position and resets its counter of moves.

It means that the hero will be able to move again a block that could only be moved a limited number of times even if the limit was reached.

block:is_pushable()

Returns whether this block can be pushed.

This property is independent of whether or not the block was already moved its maximum number of times.

  • Return value (boolean): true if this block can be pushed.

block:set_pushable([pushable])

Sets whether this block can be pushed.

This property is independent of whether or not the block was already moved its maximum number of times.

  • pushable (boolean): true to make this block pushable. No value means true.

block:is_pullable()

Returns whether this block can be pulled.

This property is independent of whether or not the block was already moved its maximum number of times.

  • Return value (boolean): true if this block can be pulled.

block:set_pullable([pullable])

Sets whether this block can be pulled.

This property is independent of whether or not the block was already moved its maximum number of times.

  • pullable (boolean): true to make this block pullable. No value means true.

block:get_max_moves()

Returns the maximum number of times the block can be moved.

This function returns the maximum moves value that was set at creation time or by block:set_max_moves(), no matter if the block was moved then.

  • Return value (number or nil): How many times the block can be moved. nil means unlimited.

block:set_max_moves(max_moves)

Sets the maximum number of times the block can be moved.

This resets the remaining allowed moves.

  • maximum_moves (number or nil): How many times the block can be moved. nil means unlimited.

Events inherited from map entity

Events are callback methods automatically called by the engine if you define them.

Blocks are particular map entities. Therefore, they inherit all events from the type map entity.

See Events of all entity types to know these events.

Events of the type block

The following events are specific to blocks.

block:on_moving()

Called when the hero starts moving the block of a step.

block:on_moved()

Called when the hero has just moved this block of a step.

Deprecated methods of the type block

The following methods are deprecated and may be removed it future releases.

block:get_maximum_moves()

Same as block:get_max_moves().

  • Return value (number): How many times the block can be moved. nil means unlimited.
Warning
This method is deprecated since Solarus 1.6 because the corresponding parameter maximum_moves of map:create_block() is also deprecated.

Use block:get_max_moves() instead.

block:set_maximum_moves(maximum_moves)

Same as block:set_max_moves().

  • maximum_moves (number): How many times the block can be moved. nil means unlimited.
Warning
This method is deprecated since Solarus 1.6 because the corresponding parameter maximum_moves of map:create_block() is also deprecated.

Use block:set_max_moves() instead.