Advertisement
osmarks

OC Robot Name Thing

Jan 24th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. local h = http.get "https://raw.githubusercontent.com/MightyPirates/OpenComputers/master-MC1.7.10/src/main/resources/assets/opencomputers/robot.names"
  2. local name_list = h.readAll()
  3. h.close()
  4.  
  5. local names = {}
  6.  
  7. local regex = "([^\n]+)" -- dark magic taken from StackOverflow and also technically a pattern and not regex
  8. for line in name_list:gmatch(regex) do
  9.     local comment_pos = line:find "#"
  10.     if comment_pos then line = line:sub(1, comment_pos - 1) end
  11.     local line = line:gsub(" *$", "")
  12.     if #line > 0 then
  13.         table.insert(names, line)
  14.     end
  15. end
  16.  
  17. local name = names[math.random(1, #names)]
  18. print(name)
  19. os.setComputerLabel(name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement