Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- # # # # Configuration # # # #
- local CONFIG_FILENAME = [[C:\Users\Rodrigo\Desktop/script.log]] -- "/path/to/file.log"
- -- # # # # Utility functions # # # #
- local function file_exists(name)
- local f = io.open(name, "r")
- if f ~= nil then io.close(f) return true else return false end
- end
- local function create_file(name)
- if file_exists(name) then
- print("Error: file \"" .. name .. "\" already exists!")
- return false
- end
- local f, message = io.open(name, "w")
- if f ~= nil then
- return f
- else
- print(message)
- return false
- end
- end
- local function read_last_line(filename)
- if not file_exists(filename) then return "" end
- local last_line
- for line in io.lines(filename) do
- last_line = line
- end
- return last_line
- end
- local function get_arguments(line)
- print(line .. "<<")
- local list = {}
- for word in string.gmatch(line, "%S+") do
- list[#list + 1] = word
- end
- local unpack = table.unpack or unpack -- Lua compatibility
- return unpack(list)
- end
- -- # # # # Init # # # #
- -- create a new file if it deosn't exist
- local handle
- if not file_exists(CONFIG_FILENAME) then
- handle = create_file(CONFIG_FILENAME)
- else
- handle = io.open(CONFIG_FILENAME, "a")
- end
- -- get last saved indexes
- local line = read_last_line(CONFIG_FILENAME)
- local _i, _j, _k = get_arguments(line)
- if not (_i and _j and _k) then
- _i, _j, _k = 0, 0, 0
- end
- print("Starting from indexes", _i, _j, _k)
- -- on exit event
- local last_i, last_j, last_k
- event.onexit(function()
- local str = string.format("%s %s %s\n", last_i, last_j, last_k)
- print("Last indexes used: ", str)
- print(handle)
- print(str)
- handle:write(str)
- handle:close()
- end)
- -- Pick up where we left off
- if not (typeChar and submitTheCode) then error"UNDEFINIED FUNCTIONS" end
- for i = _i, 60, 1 do
- last_i = i
- typeChar(i)
- savestate.saveslot(1)
- for j = _j, 60, 1 do
- last_j = j
- savestate.loadslot(1)
- typeChar(i)
- savestate.saveslot(2)
- for k = _k, 60, 1 do
- last_k = k
- savestate.loadslot(2)
- typeChar(i)
- submitTheCode()
- end
- end
- end
- print("Task finished!!!")
Add Comment
Please, Sign In to add comment