Skip to content

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.

Open the editor and select Starters. The first one is the intruder alarm:

starter-intruder-alarm.fsig
// 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.

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.

  • friends is a constant list of names. isFriend loops over it with for and returns true when it finds the name.
  • entity.hostile and entity.player are true or false. and and not combine them.
  • countChanged runs when the number of entities near the detector changes. When everyone has left, the alarm stops early.
  • In the detector’s form, set Events report to hostile so only monsters raise events.
  • Add a Display Module and write the last intruder on it with screen.write(...).