Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- currentScroll = 0;
- turtles = 0;
- tIds = {}
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function writeIn(x, y, text)
- local i,j = term.getSize()
- --if y < j then
- term.setCursorPos(x, y)
- write(text);
- --end
- end
- function draw()
- local x,y = term.getSize()
- clear()
- local posX, posY, posZ = gps.locate();
- print("Turtle Manager (#" .. os.getComputerID() .. ") (" .. turtles .. ")");
- rednet.open("top")
- for i = 0, x do
- term.setCursorPos(i,2)
- write("-")
- end
- for i = 0, turtles do
- --writeIn(1, 3 + (i + currentScroll) % (y - 2), "#" .. index);
- if(tIds[i] ~= nil) then
- writeIn(1, 3 + i, tIds[i .."label"] .. " (#" ..tIds[i]..")")
- end
- end
- term.
- currentScroll = (currentScroll + 1);
- end
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- while true do
- local id, message = rednet.receive(1)
- if(message ~= nil) then
- local sMessage = split(message, ":")
- if(string.sub(message, 1, 7) == "ayylmao") then
- local isNew = true;
- for i = 0, turtles do
- if(tIds[i] == id) then
- isNew = false;
- end
- end
- if(isNew)then
- tIds[turtles] = id;
- tIds[turtles .. "label"] = string.sub(message, 9, #message)
- turtles = turtles + 1;
- end
- end
- end
- draw(id, message)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement