The os_magreader component is OpenSecurity's magnetic card reader. The Lua API itself is small, but the block emits a configurable signal whenever a programmed magnetic card is swiped through it.
- Repository:
opensecurity - Component name:
os_magreader - Typical host: placed OpenSecurity magnetic card reader
local component = require("component")
local mag = component.os_magreader
if not mag then
error("os_magreader component not installed")
endWhen a valid magnetic card is swiped and the reader has enough power, it sends:
computer.signal(eventName, user, data, uuid, locked, side)Default event name:
magData
Payload fields:
user:- player display name when
magCardDisplayNameis enabled - literal
"player"when that config is disabled
- player display name when
data: the card payload stringuuid:- real card UUID normally
"-1"whenignoreUUIDsis enabled
locked:boolean: whether the card is rewrite-lockedside:number: the side from which the swipe interaction hit the block
Additional behavior:
- Swipes consume
5buffer energy before the signal is emitted. - The block plays the
opensecurity:card_swipesound when a magnetic card is used while idle. - If the card has no stored
datatag, no signal is emitted.
- Syntax:
mag.greet() - Returns:
string - Purpose: Returns the built-in OpenSecurity greeting.
- Syntax:
mag.setEventName(name) - Returns:
boolean - Purpose: Changes the signal event name used for future swipes.
Parameters:
name:string: new signal name.
Behavior:
- The name is stored in NBT.
- After world reload, empty or missing values fall back to
magData.
Example:
assert(mag.setEventName("doorCard"))local event = require("event")
mag.setEventName("doorCard")
while true do
local _, _, _, eventName, user, data, uuid, locked, side = event.pull("computer.signal")
if eventName == "doorCard" then
print(user, data, uuid, locked, side)
end
endcomponentos_cardwriter