Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- this is the startup script for signal computers
- ----| config |----------------------------
- local MODEM_SIDE = "top"
- local SIGNAL_SIDE = "back" -- the side connected to the signal
- local CENTRAL_CPU_ID = 125 -- the id of the computer at spawn
- ----| setup |----------------------------
- local actionEnum = {
- GET_SIGNAL_STATE = "GET_SIGNAL_STATE",
- SENSOR_CHANGE = "SENSOR_CHANGE",
- }
- ----| functions |----------------------------
- function receiveSignal() -- waits for commands from central cpu
- while true do
- print("Waiting for a command...")
- local id, state = rednet.receive()
- if id == CENTRAL_CPU_ID then
- if state == true then -- activate signal
- print("Activating signal...")
- redstone.setOutput(SIGNAL_SIDE, true)
- elseif state == false then -- deactivate signal
- redstone.setOutput(SIGNAL_SIDE, false)
- print("Deactivating signal...")
- end
- end
- end
- end
- ----| main |----------------------------
- rednet.open(MODEM_SIDE)
- print("Rednet opened.")
- -- get the immediate signal state
- print("Getting the immediate state...")
- rednet.send(CENTRAL_CPU_ID, actionEnum.GET_SIGNAL_STATE)
- local id, immediateState = rednet.receive()
- redstone.setOutput(SIGNAL_SIDE, immediateState)
- print("The signal state is currently set to " .. tostring(immediateState))
- -- listen for signal state changes
- receiveSignal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement