Intruder alarm
You need: a computer, a Network Repeater, an Entity Detector named gate and an Alarm Module named siren, all
linked through the repeater. The first automation guide shows every
step.
The starter
Section titled “The starter”Open the editor and select Starters. The first one is the intruder alarm:
// Starter: Intruder alarm (computer)// Sounds the Alarm Module "siren" when someone walks up to the Entity Detector "gate".// Name the two devices in their forms, link them to this computer, then start the program.const gate = detectors.named("gate")const siren = alarms.named("siren")
// "on" runs the code between { and } every time the event happens.// entity tells you who arrived: entity.name, entity.hostile, entity.player and more.on gate.entityEnter(entity) { print(entity.name + " is at the gate!") siren.activate()}It sounds for every arrival, including you and your pets.
Only monsters and strangers
Section titled “Only monsters and strangers”Let’s make it smarter: ignore friends and animals.
const gate = detectors.named("gate")const siren = alarms.named("siren")const friends = ["Steve", "Alex"]
fn isFriend(name) { for friend in friends { if friend is name { return true } } return false}
on gate.entityEnter(entity) { if entity.hostile { print("Monster at the gate: " + entity.type) siren.activate() } else if entity.player and not isFriend(entity.name) { print("Stranger at the gate: " + entity.name) siren.activate() }}
on gate.countChanged(count, previous) { if count is 0 { siren.deactivate() }}Put your own name and your friends’ names into the friends list.
How it works
Section titled “How it works”friendsis a constant list of names.isFriendloops over it withforand returnstruewhen it finds the name.entity.hostileandentity.playeraretrueorfalse.andandnotcombine them.countChangedruns when the number of entities near the detector changes. When everyone has left, the alarm stops early.
Try next
Section titled “Try next”- In the detector’s form, set Events report to
hostileso only monsters raise events. - Add a Display Module and write the last intruder on it with
screen.write(...).