Gokborg

TurtleBuilderProgram

Nov 25th, 2020 (edited)
434
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2.  
  3. if #tArgs ~= 1 then
  4.     print("Usage: gkbuilder <filename>")
  5.     return
  6. end
  7.  
  8. function parse_gkbuild(filename)
  9.     f = fs.open(filename, "r")
  10.    
  11.     current = f.read()
  12.    
  13.     --Leaves on the last digit which isn't a number
  14.     function parse_num()
  15.         local num_str = ""
  16.         while tonumber(current) do
  17.             num_str = num_str..current
  18.             current = f.read()
  19.         end
  20.         return tonumber(num_str)
  21.     end
  22.    
  23.     layers_total = parse_num()
  24.     if layers_total == nil then
  25.         print("The formatting of the file is incorrect! Did you forget the first number is the total number of layers?")
  26.     end
  27.     print(layers_total)
  28.     map = {}
  29.     for i=1, layers_total do
  30.         layer = {}
  31.         while current ~= ';' do
  32.             current = f.read()
  33.             table.insert(layer, parse_num())
  34.         end
  35.         layer_str = ""
  36.         for j=1, #layer do
  37.             layer_str = layer_str..tostring(layer[j])..","
  38.         end
  39.         print(layer_str)
  40.         table.insert(map, layer)
  41.     end
  42.     print(#map)
  43.     map_str = ""
  44.     for i=1, #map do
  45.         layer_str = ""
  46.         for j=1, #map[i] do
  47.             layer_str = layer_str..tostring(map[i][j])..","
  48.         end
  49.         layer_str = layer_str.."\n"
  50.         print(layer_str)
  51.     end
  52.     return map
  53. end
  54.  
  55. print(parse_gkbuild(tArgs[1]))
RAW Paste Data