Solarus quests
1.6
Quest maker's reference
|
A switch is a button that can be activated to trigger a mechanism.
This type of map entity can be declared in the map data file. It can also be created dynamically with map:create_switch().
A switch may be activated by the hero, by a block or by a projectile, depending on its subtype. The following subtypes of switches are available:
When a switch is activated, the event switch:on_activated() is called. Define that event to implement what happens: opening a door, showing a chest, etc.
Some switches get inactivated when the hero (or the entity that activated them) leaves them. In this case, when the switch is inactivated, the event switch:on_inactivated() is called.
The size of a switch is always 16x16 pixels. Its sprite can be defined at creation time, as well as the sound played when it gets activated.
Switches are particular map entities. Therefore, they inherit all methods from the type map entity.
See Methods of all entity types to know these methods.
The following methods are specific to switches.
Returns whether this is a walkable switch.
true
if this switch is a walkable one.Returns whether this switch is activated.
true
if this switch is currently activated.Sets whether this switch is activated or not.
The change is quiet and immediate: no sound is played and no event is triggered.
activated
(boolean, optional): true
to make the switch activated, false
to make is inactivated. No value means true
.Returns whether this switch is current locked.
When a switch is locked, its state cannot change anymore: it can no longer be activated or inactivated by other entities. However, it can still changed programmatically by calling switch:set_activated().
true
if this switch is currently activated.Locks this switch in its current state or unlocks it.
When a switch is locked, its state cannot change anymore: it can no longer be activated or inactivated by other entities. However, it can still changed programmatically by calling switch:set_activated().
locked
(boolean, optional): true
to lock the switch, false
to unlock it. No value means true
.Events are callback methods automatically called by the engine if you define them.
Switches are particular map entities. Therefore, they inherit all events from the type map entity.
See Events of all entity types to know these events.
The following events are specific to switches.
Called when this switch has just been turned on.
This is the right place to define the action that you want your switch to perform.
Called when a switch has just been turned off.
Called when an entity placed on a switch (like the hero or a block) has just left the switch, regardless of whether the switch was activated or not.