doodle/dev-assets/doodads/on-off/state-block-blue.js
Noah Petherbridge 7b3aec0fef Fix Two-State Blocks & Collision Detection
* Two-state Buttons now also subscribe to the state change message, so
  other on/off buttons in the same level update to match the state of
  the button that was hit.
* Add lock mutexes around the scripting engine to protect from
  concurrent event handlers.
2020-01-02 17:58:22 -08:00

24 lines
409 B
JavaScript

// Blue State Block
function main() {
Self.SetHitbox(0, 0, 33, 33);
// Blue block is ON by default.
var state = true;
Message.Subscribe("broadcast:state-change", function(newState) {
state = !newState;
// Layer 0: ON
// Layer 1: OFF
Self.ShowLayer(state ? 0 : 1);
});
Events.OnCollide(function(e) {
if (e.Actor.IsMobile() && e.InHitbox) {
if (state) {
return false;
}
}
});
}