Advertisement
DOGGYWOOF

Background running code v2

Jan 1st, 2024
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local fileToMonitor = "yourfile.txt" -- Change this to your file name
  2. local interval = 5 -- Interval in seconds
  3.  
  4. local function monitorFile()
  5. while true do
  6. if fs.exists(fileToMonitor) then
  7. -- Your code to send a message or perform actions when the file is found
  8. -- For example: redstone.setOutput("back", true)
  9. else
  10. -- Your code to run when the file is not found
  11. -- For example: shell.run("program_to_execute")
  12. end
  13.  
  14. os.startTimer(interval)
  15. os.pullEvent("timer")
  16. end
  17. end
  18.  
  19. local monitorThread = coroutine.create(monitorFile)
  20. coroutine.resume(monitorThread)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement