This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
lukasdragon's profile picture

Re trigger code after run?

Started by lukasdragon, 11 April 2014 - 01:00 AM
lukasdragon #1
Posted 11 April 2014 - 03:00 AM
Hello, I am creating a remote controlled computer system for my server & base, However I need to re "prime" the code after each trigger of the wifi code "detectors"
Heres some code if it helps :)/>

-- #Clears the screen
  term.clear()
  term.setCursorPos(1, 1)
  -- Opens any modem(s) connected to the computer
local function openRednet()
  for _,side in ipairs({"top", "bottom", "front", "left", "right", "back"}) do
		if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
		  rednet.open(side)
		  return side
		end
  end
end

modemSide = openRednet()
-- Now for the recieving code
id, msg = rednet.receive()
-- Events caused by the different commands
-- Power Events
-- shutdown Event
if msg == "os.shutdown()01" then
os.shutdown()
end
-- Restart Event
if msg == "os.reboot()02" then
os.reboot()
end
-- disk events
-- Play Disk Event
if msg == "disk.playAudio03" then
   -- Start Of Code
	disk.playAudio("top")
disk.playAudio("bottom")
disk.playAudio("left")
disk.playAudio("right")
disk.playAudio("front")
disk.playAudio("back")
   -- End Of code
  end
-- Disk eject
if msg == "disk.eject04" then
-- Start Of Code
  disk.eject("top")
  disk.eject("bottom")
  disk.eject("left")
  disk.eject("right")
  disk.eject("front")
  disk.eject("back")
-- End Of code
end


end
Bomb Bloke #2
Posted 11 April 2014 - 09:03 AM
while true do  -- Start a loop that repeats indefinitely.
  -- Now for the recieving code
  id, msg = rednet.receive()

  if msg == "os.shutdown()01" then
    os.shutdown()
  end
  .
  .
  .
end
lukasdragon #3
Posted 11 April 2014 - 03:32 PM
I thought something like that would do it but I was unsure lol,