fyrkantis

ScheduleDestination

Mar 14th, 2025 (edited)
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. function scheduleFromFile(path)
  2.     local file = fs.open(path, "r")
  3.     local body = file.readAll()
  4.     file.close()
  5.     return textutils.unserialize(body)
  6. end
  7. function splitWord(target, word)
  8.     local i, j = string.find(target, word)
  9.     if i == nil then return target end
  10.     return string.sub(target, 1, i - 1), string.sub(target, j + 1, -1)
  11. end
  12.  
  13. schedule = scheduleFromFile("green.line")
  14. entries = schedule.entries
  15. progress = schedule.progress
  16. if progress == nil then progress = 1 end
  17. stations = {}
  18. label = nil
  19. for i=1, #entries do
  20.     local entry = entries[((i + progress - 1) % #entries) + 1]
  21.     if entry.instruction.id == "create:destination" then
  22.         stations[#stations + 1] = entry.instruction.data.text
  23.     elseif entry.instruction.id == "create:rename" then
  24.         label = entry.instruction.data.text
  25.     end
  26. end
  27.  
  28. name, andName = splitWord(label, " and ")
  29. if andName == nil then
  30.     name, andName = splitWord(label, " via ")
  31. end
  32.  
  33. print(textutils.serialize(stations))
  34. print(name)
  35. print(andName)
Advertisement
Add Comment
Please, Sign In to add comment