Advertisement
DOGGYWOOF

Background running code

Jan 1st, 2024 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local file_path = "/path/to/your/file.txt" -- Replace this with your file's path
  2. local interval = 5 -- Adjust the interval in seconds
  3.  
  4. local function checkFile()
  5.     while true do
  6.         if not fs.exists(file_path) then
  7.             print("File not found. Running code...")
  8.             -- Insert your code here to execute if the file is not found
  9.             -- Example: shell.run("your_script")
  10.             -- Replace "your_script" with the script or command you want to execute
  11.            
  12.             return -- Exit the function after running the code
  13.         end
  14.         os.startTimer(interval) -- Set the timer to check again after the interval
  15.         os.pullEvent("timer") -- Wait for the timer event
  16.     end
  17. end
  18.  
  19. -- Start the background process
  20. parallel.waitForAny(checkFile, function() os.pullEvent("terminate") end)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement