Text File:
1. No blah blahing
2. Make sure to blah blah
3. Don't blah blah
4. Have fun! :D/>
Monitor:
–SERVER RULES–
1. No blah blahing
2. Make sure to blah blah
etc, etc.
Thank you for your time :)/>
--[[
@description "Converts whole file into table"
@param filename, string
@return table
--]]
function loadTable( filename )
if fs.exists(filename) then
local file = fs.open(filename,"r")
local content = {}
local line = file.readLine()
repeat
table.insert(content,line)
line = file.readLine()
until line == nil
file.close()
return content
else
error("File doesn't exist: "..filename, 2)
end
end
Use that function to get the files' content stored in a table.
local content = loadTable( "somefile" )
for i = 1, #content do
print( content[i] )
end
Well yeah ofcourse you can, First you should load the files content into a table like this….
local m = peripheral.wrap("right")
function loadTable( filename )
if fs.exists(filename) then
local file = fs.open(filename,"r")
local content = {}
local line = file.readLine()
repeat
table.insert(content,line)
line = file.readLine()
until line == nil
file.close()
return content
else
error("File doesn't exist: "..filename, 2)
end
end
function lineBreak()
local x, y = m.getCursorPos()
m.setCursorPos(1, y+1)
end
local content = loadTable( "disk/rules.txt" )
for i = 1, #content do
m.write( content[i])
lineBreak()
end
Some Group:
- 6665464
- 8675309
- 31415
Blacklist:
- '30208:1:byp-prot '
- '25356:0:byp-prot '
- '9263:0:byp-prot '
- '2414:5:byp-prot '
- '407:0:byp-prot '
- '237:0:byp-prot '
- '7778:0:byp-prot '
Blacklist Placement: []
-464648684
etc.
- '30208:1:byp-prot '
- '25356:0:byp-prot '
- '9263:0:byp-prot '
- '2414:5:byp-prot '
- '407:0:byp-prot '
- '237:0:byp-prot '
- '7778:0:byp-prot '
Currently, the table loader loops through the file dumping every line it reads into a table, until it reaches the end.
You'd want to split that into two loops: One which reads until it hits the line "Blacklist:" (without putting anything in the table), and one that reads until it hits the line "Blacklist Placement: []" (while putting stuff in the table).
function loadTable(filename)
if fs.exists(filename) then
local file = fs.open(filename,"r")
local content = {}
local line = file.readLine() -- Read the first line from the file.
repeat -- Loops the code inside...
table.insert(content,line) -- Puts the last line read into the table.
line = file.readLine() -- Reads another line from the file.
until line == nil -- ... until we tried to read a non-existent line (the end of the file was reached).
file.close()
return content
else
error("File doesn't exist: "..filename, 2)
end
end
local function loadTable(filename)
if fs.exists(filename) then
local file = fs.open(filename,"r")
local content = {}
local line
repeat -- Loops the below...
line = file.readLine() -- Reads a line from the file.
until line == "Blacklist:" -- .. until we got the "Blacklist:" line.
line = file.readLine() -- Get the next line (some of the data we actually want).
repeat -- Loops the below...
table.insert(content,line) -- Puts the last line read into the table.
line = file.readLine() -- Reads another line from the file.
until line == "Blacklist Placement: []" -- ... until we read past the desired block.
return content
else
error("File doesn't exist: "..filename, 2)
end
end