Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getPos(unit)
- file = io.open("MTextFieldDir/"..unit..".txt", "r")
- x = tonumber(file:read("*l"))
- y = tonumber(file:read("*l"))
- text = file:read("*l")
- if file:read("*l") == "true" then bVisible = true else bVisible = false end
- return bVisible, text, x, y
- end
- ------------------------------------------------------------------
- function setText(unit, text)
- local tLines = {}
- if string.len(text) > 20 then
- text = string.sub(text, 1, 20)
- end
- file = io.open("MTextFieldDir/"..unit..".txt", "r")
- table.insert(tLines, 1, file:read("*l"))
- table.insert(tLines, 2, file:read("*l"))
- table.insert(tLines, 3, file:read("*l"))
- table.insert(tLines, 4, file:read("*l"))
- tLines[3] = text
- file:close()
- file = io.open("MTextFieldDir/"..unit..".txt", "w")
- file:write(tLines[1].."\n"..tLines[2].."\n"..tLines[3].."\n"..tLines[4])
- file:close()
- bVisible, text, x, y = getPos(unit)
- if bVisible == true then
- term.setCursorPos(x, y)
- io.write("+--------------------+")
- term.setCursorPos(x, y + 1)
- io.write("|")
- term.setCursorPos(x, y + 2)
- io.write("+--------------------+")
- term.setCursorPos(x + 1, y + 1)
- io.write(text)
- term.setCursorPos(x + 21, y + 1)
- io.write("|")
- term.setCursorPos(1, y + 3)
- end
- end
- ------------------------------------------------------------------
- function newTextField(unit, x, y)
- if not fs.exists("MTextFieldDir") then
- fs.makeDir("MTextFieldDir")
- end
- file = io.open("MTextFieldDir/"..unit..".txt", "w")
- file:write(x.."\n"..y.."\n\nfalse")
- file:close()
- end
- ------------------------------------------------------------------
- function setVisible(unit, bVisible)
- blah, text, x, y = getPos(unit)
- local tLines = {}
- if bVisible == true then
- term.setCursorPos(x, y)
- io.write("+--------------------+")
- term.setCursorPos(x, y + 1)
- io.write("|")
- term.setCursorPos(x, y + 2)
- io.write("+--------------------+")
- term.setCursorPos(x + 1, y + 1)
- io.write(text)
- term.setCursorPos(x + 21, y + 1)
- io.write("|")
- term.setCursorPos(1, y + 3)
- file = io.open("MTextFieldDir/"..unit..".txt", "r")
- table.insert(tLines, 1, file:read("*l"))
- table.insert(tLines, 2, file:read("*l"))
- table.insert(tLines, 3, file:read("*l"))
- table.insert(tLines, 4, file:read("*l"))
- file:close()
- tLines[4] = "true"
- file = io.open("MTextFieldDir/"..unit..".txt", "w")
- file:write(tLines[1].."\n"..tLines[2].."\n"..tLines[3].."\n"..tLines[4])
- file:close()
- elseif bVisible == false then
- term.setCursorPos(x, y)
- print(" ")
- print(" ")
- print(" ")
- term.setCursorPos(1, y + 3)
- file = io.open("MTextFieldDir/"..unit..".txt", "r")
- table.insert(tLines, 1, file:read("*l"))
- table.insert(tLines, 2, file:read("*l"))
- table.insert(tLines, 3, file:read("*l"))
- table.insert(tLines, 4, file:read("*l"))
- file:close()
- tLines[4] = "false"
- file = io.open("MTextFieldDir/"..unit..".txt", "w")
- file:write(tLines[1].."\n"..tLines[2].."\n"..tLines[3].."\n"..tLines[4])
- file:close()
- end
- end
- ------------------------------------------------------------------
- function getText(unit)
- file = io.open("MTextFieldDir/"..unit..".txt", "r")
- text = file:read("*l")
- text = file:read("*l")
- text = file:read("*l")
- file:close()
- return text
- end
Advertisement
Add Comment
Please, Sign In to add comment