Jump to content




Help Me!


  • You cannot reply to this topic
4 replies to this topic

#1 TableCraft0R

  • Members
  • 63 posts

Posted 22 May 2013 - 11:55 PM

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

#2 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 23 May 2013 - 12: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?

#3 TableCraft0R

  • Members
  • 63 posts

Posted 23 May 2013 - 12:19 AM

Like your button listener..

#4 Mackan90096

  • Signature Abuser
  • 518 posts
  • LocationIn my basement.

Posted 23 May 2013 - 12:27 AM

What?
Like a thing that detects a keyboard press?

Oh, try using the wiki aswell;

computercraft.info/wiki


#5 LordIkol

  • Members
  • 197 posts
  • LocationSwitzerland

Posted 23 May 2013 - 03: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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users