i will release a small but useful tool to manage the read / write file I / O system in lua commonly used in many scripts also creates a backup copy of the edited file (in write mode)
copy in questlib.lua:
Code:
DATA_READ = 0 DATA_WRITE = 1 function data_tool(DATA_MODE, DATA_FILE, DATA_LINE) local x = 1 local file = "" if DATA_MODE == DATA_READ then file = io.open(DATA_FILE, "r") while true do local line = file:read("*l") if line == nil then break end text = string.gsub(line, "\n", "") if x == DATA_LINE then io.close(file) return text end x = x + 1 end io.close(file) elseif DATA_MODE == DATA_WRITE then os.rename(DATA_FILE, DATA_FILE..".BAK") file = io.open(DATA_FILE, "w") file:write(DATA_LINE) io.close(file) os.execute("chmod 777 "..DATA_FILE) end end
first be copied to questlib.lua and we should be all right here ... xD
VARIABLES:
DATA_MODE = indicates how to act on the file (DATA_READ / 0 = read, DATA_WRITE / 1 = write)
Data_file = specifies the file on which to act (absolute path)
DATA_LINE = in read mode indicates the number of the line to be read, in write mode the text to write.
as use read / write:
as an example we use the file: file.txt located in the path / home / game /
Code:
read example: local data = "/home/game/file.txt" local linea = 3 local result = data_tool(DATA_READ, data, linea) write example: local data = "/home/game/file.txt" local linea = "ciao" data_tool(DATA_WRITE, data, linea)
in the second case we wrote in file.txt ciao
I hope I was clear enough and useful
P.S.: if you want you can add the flag to increase the functionality, but this is up to you ...
enjoy
d3m0n3