Amaraticando

http://tasvideos.org/forum/viewtopic.php?t=18780

Jan 15th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. -- # # # #  Configuration # # # #
  2. local CONFIG_FILENAME = [[C:\Users\Rodrigo\Desktop/script.log]] -- "/path/to/file.log"
  3.  
  4.  
  5. -- # # # #  Utility functions # # # #
  6. local function file_exists(name)
  7.   local f = io.open(name, "r")
  8.   if f ~= nil then io.close(f) return true else return false end
  9. end
  10.  
  11. local function create_file(name)
  12.   if file_exists(name) then
  13.     print("Error: file \"" .. name .. "\" already exists!")
  14.     return false
  15.   end
  16.  
  17.   local f, message = io.open(name, "w")
  18.   if f ~= nil then
  19.     return f
  20.   else
  21.     print(message)
  22.     return false
  23.   end
  24. end
  25.  
  26. local function read_last_line(filename)
  27.   if not file_exists(filename) then return "" end
  28.  
  29.   local last_line
  30.   for line in io.lines(filename) do
  31.     last_line = line
  32.   end
  33.  
  34.   return last_line
  35. end
  36.  
  37. local function get_arguments(line)
  38.   print(line .. "<<")
  39.   local list = {}
  40.   for word in string.gmatch(line, "%S+") do
  41.     list[#list + 1] = word
  42.   end
  43.  
  44.   local unpack = table.unpack or unpack  -- Lua compatibility
  45.   return unpack(list)
  46. end
  47.  
  48.  
  49. -- # # # # Init # # # #
  50.  
  51. -- create a new file if it deosn't exist
  52. local handle
  53. if not file_exists(CONFIG_FILENAME) then
  54.   handle = create_file(CONFIG_FILENAME)
  55. else
  56.   handle = io.open(CONFIG_FILENAME, "a")
  57. end
  58.  
  59. -- get last saved indexes
  60. local line = read_last_line(CONFIG_FILENAME)
  61. local _i, _j, _k = get_arguments(line)
  62. if not (_i and _j and _k) then
  63.   _i, _j, _k = 0, 0, 0
  64. end
  65. print("Starting from indexes", _i, _j, _k)
  66.  
  67. -- on exit event
  68. local last_i, last_j, last_k
  69.  
  70. event.onexit(function()
  71.   local str = string.format("%s %s %s\n", last_i, last_j, last_k)
  72.   print("Last indexes used: ", str)
  73.  
  74.   print(handle)
  75.   print(str)
  76.   handle:write(str)
  77.   handle:close()
  78. end)
  79.  
  80. -- Pick up where we left off
  81.  
  82. if not (typeChar and submitTheCode) then error"UNDEFINIED FUNCTIONS" end
  83.  
  84. for i = _i, 60, 1 do
  85.   last_i = i
  86.   typeChar(i)
  87.   savestate.saveslot(1)
  88.  
  89.   for j = _j, 60, 1 do
  90.     last_j = j
  91.     savestate.loadslot(1)
  92.     typeChar(i)
  93.     savestate.saveslot(2)
  94.    
  95.     for k = _k, 60, 1 do
  96.       last_k = k
  97.       savestate.loadslot(2)
  98.       typeChar(i)
  99.       submitTheCode()
  100.     end
  101.    
  102.   end
  103.  
  104. end
  105.  
  106. print("Task finished!!!")
Add Comment
Please, Sign In to add comment