61 posts
Posted 23 May 2013 - 12:55 AM
Help needed for my new OS:
CC-DOS
I want to:
- Read a specific line in configuration
- Button listener
- Write in a specific line in config
- Draggable window
I will write your name in About Window as: this os becomes possible because of yourname,myname
695 posts
Location
In my basement.
Posted 23 May 2013 - 01:16 AM
Hi there!
There are people who are willing to teach you.
But remember: We are NOT your coding monkeys.
What that means is that we wont code things for you, but we are willing to help you.
What do you mean with button listener?
61 posts
Posted 23 May 2013 - 01:19 AM
Like your button listener..
695 posts
Location
In my basement.
Posted 23 May 2013 - 01:27 AM
What?
Like a thing that detects a keyboard press?
Oh, try using the wiki aswell;
computercraft.info/wiki
199 posts
Location
Switzerland
Posted 23 May 2013 - 04:33 AM
check this code just typed it together to give you a clue how you could do it
local function readline(fname,line)
local file = fs.open(fname, "r") -- open the file
if file then --check if file exists
local fContent = file.readAll() --read contents
local fTable = textutils.unserialize(fContent) -- put content to a table (be careful this only works if the content was created by serializing a table
file.close() -- close file handle
return fTable[line] -- return table entry that is equal to the line in the file
else -- if file does not exists
return "file not Found" -- give errormessage
end
end
local function writetoline(fname,insertstring,line) -- with this you create the file line by line.
local file = fs.open(fname, "r") -- open file
if file then -- check if exists
local fContent = file.readAll() -- if exists read content
file.close() -- close file handle
fTable = textutils.unserialize(fContent) -- read content of the file to table
fTable[line] = insertstring -- insert new line or override existing line
else -- if file does not exists
fTable = {insertstring} --create a table with the text you want to add this will be added to line 1 of your file
end
file = fs.open(fname, "w") --open file for saving
file.write(textutils.serialize(fTable)) -- convert table to a string that we can read with unserialize
file.close() -- close filehandle
end
writetoline("test.txt","dies",1) -- write "dies" to line 1
writetoline("test.txt","ist",2) -- write "ist" to line 2
writetoline("test.txt","ein",3)
writetoline("test.txt","beispiel",4)
writetoline("test.txt","Moep",5)
bla = readline("test.txt",5)) -- read line 5
print(bla) -- print the variable
hope that helps
greets Loki