Rnen10

Iron Golem Counter

May 29th, 2020 (edited)
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | Gaming | 0 0
  1. -- Made by Rnen10
  2. -- If problems/questions feel free to contact me
  3. -- https://twitter.com/Rnen10
  4. -- rnen. (Evan#7181)  on discord
  5.  
  6. -- Iron golem murder counter program.
  7. -- Auto-Update program for this and display can be found at https://pastebin.com/WsVbRvmL (download as startup)
  8. -- WriteToMon "display" = https://pastebin.com/FxkS233S
  9.  
  10. term.clear()
  11. term.setCursorPos(1,1)
  12. print("Started counting murder...")
  13.  
  14. local count = 0
  15.  
  16. local function WriteToMon(Int)
  17.     if fs.exists("display") then
  18.         shell.run("display "..Int)
  19.     end
  20. end
  21.  
  22. local function ReadFile()
  23.     if fs.exists("countFile") then
  24.         print("Existing count found! Resuming...")
  25.         local file = fs.open("countFile","r")
  26.         sleep(0.1)
  27.         local data = file.readAll()
  28.         sleep(0.1)
  29.         file.close()
  30.         sleep(0.1)
  31.         count = textutils.unserialize(data)
  32.         print("I've murdered "..count.." innocent golems")
  33.         WriteToMon(count)
  34.     else
  35.         local file = fs.open("countFile","w")
  36.         sleep(0.1)
  37.         file.write(textutils.serialize(count))
  38.         sleep(0.1)
  39.         file.close()
  40.     end
  41. end
  42.  
  43. local function SaveFile()
  44.     local file = fs.open("countFile","w")
  45.     sleep(0.1)
  46.     file.write(textutils.serialize(count))
  47.     sleep(0.1)
  48.     file.close()
  49. end
  50.  
  51. --Main Loop
  52.  
  53. ReadFile()
  54.  
  55. while true do
  56.     os.pullEvent("redstone")
  57.     if redstone.getInput("right") then
  58.         count = count + 1
  59.     end
  60.     SaveFile()
  61.     print("I've murdered "..count.." innocent golems")
  62.     WriteToMon(count)
  63.     sleep(1)
  64. end
Advertisement
Add Comment
Please, Sign In to add comment