Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Plazter

[Solved]TodoList, Read/Write To anotherfile

Question

Hello folks!, i've been browsing, searching for hours now,  tried and tested, done whatever i could do, i have been trying to find/make my code read from another file, that it also eventually should save to, but havent  gotten that far yet ^^, the reason i want to do it with another file, is because, the server i play on crash, or if the area aint loaded, the computer needs to be rebooted, and i would like to be able to add new Todo's as i go.

I must admit, this is a stupid and hard wall, and its properly VERY simple, once i get it :b, none the less, heres the code im at. 

--[[                                            [Requirements]                    ]]--
component = require("component")
event = require("event")
gpu = component.gpu
computer = component.computer
keyboard = require("keyboard")
term = require("term")
fs = require("filesystem")



Scolors = { black = 0x000000, white = 0xf8f8ff, blue = 0x0000ff, lightGray = 0xd9d9d9, red = 0xff0000,
purple = 0x9b30ff, carrot = 0xffa500, magenta = 0xcd00cd, lightBlue = 0x87cefa, yellow = 0xffff00,
lime = 0x32cd32, pink = 0xffc0cb, gray = 0x696969, brown = 0x8b4500, green = 0x006400, cyan = 0x008b8b,
olive = 0x6b8e23, gold = 0x8b6914, orangered = 0xdb4e02, diamond = 0x0fa7c7,crimson = 0xaf002a,fuchsia = 0xfd3f92,
folly = 0xff004f, frenchBlue = 0x0072bb, lilac = 0x86608e, flax = 0xeedc82, darkGray = 0x563c5c,
englishGreen = 0x1b4d3e, eggplant = 0x614051, deepPink  = 0xff1493, ruby = 0x843f5b, orange = 0xf5c71a,
lemon = 0xffd300, darkBlue = 0x002e63, bitterLime = 0xbfff00 }


--[[                                            [Var]                             ]]--

--Line = 4

--[[                                            [Table for list]                  ]]--

Todo = {}

--[[                                            [Functions]                       ]]--

function getTodo()
	for line in io.lines("TodoList.txt") do
		table.insert(Todo, line)
	end
end

--[[                                            [Exit Key]                        ]]--

function Exit()
	if x ~= nil and y ~= nil then
		if x >= 12 and x <= 18 and y == 1 then
			os.exit()
		elseif x >= 16 and x<=20 and y == 1 then
			os.execute("edit todo")
		end
	end
end


--[[                                             [MODE KEY]                       ]]--

function mode()
    h,w = gpu.getResolution()
	if x ~= nil and  y ~= nil then                    
		gpu.set(h-10,w, "X: ".. x.. " Y: ".. y)
		os.sleep(1)
			if x >= 1 and x <= 9  and y == 1 then
				Add()        
				os.sleep(1)
			end
		term.clear()
		os.sleep(.5)    
	end
end

--[[                                             [ADD KEY]]                       ]]--

function Add()
	h, w = gpu.getResolution()
	gpu.setForeground(Scolors.orange)
	gpu.set(1, w,"Enter Todo: ")
	term.setCursor(13,w)
	
	data = io.open("TodoList.txt","a")
	input = io.read()
		if input then
			data:write(input.."\n")
		end
	data:close()
end

--[[                                            [Import Key]                      ]]--

function Import()
	if x ~= nil and y ~= nil then
		if x >= 24 and x <= 31 and y == 1 then
			getTodo()
			Line = 1
			for k,v in pairs (Todo)do
				Line = Line + 1
				gpu.set(1,Line, "* "..v)
			end
		end
	end
end

--[[                                            [Clean Key]                       ]]--

function clean()
	if x ~= nil and y ~= nil then
		if x >= 36 and x <= 42 and y == 1 then	
			Line = 2
			term.clear()
		end
	end
end

--[[                                             Pre Settings                     ]]--

gpu.setBackground(Scolors.gray)
gpu.setForeground(Scolors.orange)
h, w = gpu.maxResolution()
gpu.setResolution(h/2,w/2)
term.clear()
Line = 1

--[[                                             Main Loop                        ]]--                                                                 

while true do
	gpu.set(1,1,"Add Todo! - Exit - Edit - Update - Clear")
	--[[Touch Part]]--
	_,_,x,y = event.pull(1,"touch")
	mode()
	Import()
	Exit()
	clean()
end

I Really hope theres someone out here, that feels like a good samaritan and help a fella out^^

//Regards Plazter

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.