Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local count = {}
- local scrollPos = 1
- if fs.exists("simplecounter.txt") then
- local f = fs.open("simplecounter.txt","r")
- count = textutils.unserialize(f.readAll())
- f.close()
- end
- local saveCount = function()
- local f = fs.open("simplecounter.txt","w")
- f.write(textutils.serialize(count))
- f.close()
- end
- term.clear()
- while true do
- for a, b in ipairs(count) do
- term.setCursorPos(1, 1+a-scrollPos)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.blit("x R "..string.char(24)..string.char(25).." -+", "fffffffff", "8f8f88f88")
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.write(b.count)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.write(" "..b.name)
- end
- term.setCursorPos(1, #count+2-scrollPos)
- term.setBackgroundColor(colors.black)
- term.clearLine()
- term.blit("Add", "fff", "888")
- local event = {os.pullEvent()}
- if event[1] == "mouse_click" then
- local clickPos = event[4] + scrollPos - 1
- if clickPos == #count + 1 and event[3] >= 1 and event[3] <= 3 then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- write("Counter Name: ")
- table.insert(count, #count+1, {count=0, name=read()})
- saveCount()
- elseif clickPos <= #count then
- if event[3] == 1 then
- table.remove(count, clickPos)
- term.setBackgroundColor(colors.black)
- term.clear()
- saveCount()
- elseif event[3] == 3 then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- term.setTextColor(colors.yellow)
- term.write(count[clickPos].name)
- term.setTextColor(colors.white)
- write("\nRename Counter: ")
- count[clickPos].name = read()
- term.clear()
- saveCount()
- elseif event[3] == 5 and clickPos ~= 1 then
- table.insert(count, clickPos-1, count[clickPos])
- table.remove(count, clickPos+1)
- saveCount()
- elseif event[3] == 6 and clickPos ~= #count then
- table.insert(count, clickPos+2, count[clickPos])
- table.remove(count, clickPos)
- saveCount()
- elseif event[3] == 8 then
- count[clickPos].count = count[clickPos].count - 1
- saveCount()
- elseif event[3] == 9 then
- count[clickPos].count = count[clickPos].count + 1
- saveCount()
- end
- end
- elseif event[1] == "mouse_scroll" then
- local xSize, ySize = term.getSize()
- if event[2] == -1 and scrollPos > 1 then
- scrollPos = scrollPos - 1
- elseif event[2] == 1 and scrollPos+ySize-1 <= #count then
- scrollPos = scrollPos + 1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment