doodle/dev-assets/doodads/on-off/state-block-orange.js
Noah Petherbridge 4d08bf1d85 Switch JavaScript engine to goja
* Switch from otto to goja for JavaScript engine.
* goja supports many ES6 syntax features like arrow functions,
  const/let, for-of with more coming soon.
* Same great features as otto, more modern environment for doodads!
2022-01-16 20:09:27 -08:00

24 lines
404 B
JavaScript

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