Posted 03 December 2014 - 12:22 AM
I'm attempting to have my program print normally, then print into a window on the right of the screen, then switch back and print normally again. Every time, the program just prints the third line of text with the config of the window even with 'term.redirect(origin)'.
--Functions--
function names()
names = { "Bob", "Jim", "Jeb" }
end
function wwrite(text,color) --This function!!!
local origin = term.current()
term.redirect(myWindow)
if color ~= nil then
myWindow.setTextColor(color)
end
local posx,posy = myWindow.getCursorPos()
posy = posy + 1
myWindow.setCursorPos(1,posy)
myWindow.write(text)
term.redirect(origin)
--term.redirect(term.native())
term.setCursorPos(x,y)
end
function host(protocol)
term.redirect(term.native())
if not rednet.isOpen(side) then
rednet.open(side)
end
rednet.host(protocol,name)
term.write("Hosting the ")
if protocol == "Check-in" then
term.setTextColor(colors.green)
elseif protocol == "Alert" then
term.setTextColor(colors.red)
else
term.setTextColor(colors.orange)
end
term.write(protocol)
term.setTextColor(colors.white)
term.write(" channel.")
x,y = term.getCursorPos()
x = x - x + 1
y = y + 1
term.setCursorPos(x,y)
end
function listen(what)
if what == nil then
rednet.receive()
--elseif what
end
end
function checkin()
names()
i = 0
repeat
i = i + 2
id,message = rednet.receive("Check-in")
if message == true then
guard[i] = id
local y = id + 1
wwrite(id.."-"..names[id])
print("Guard "..id.." checked in.")
message = tostring(message)
end
--print(id.." "..message)
until nog == i
end
function startup()
guard = {}
host("Check-in")
local x,y = term.getSize()
restoreTo = term.current()
myWindow = window.create(term.current(),32,1,25,10,true)
myWindow.setBackgroundColor(colors.gray)
myWindow.clear()
wwrite("Guards:")
host("Alert")
checkin()
end
--Settings--
name = "GuardServer"
nog = 1 --Number of guards
side = "bottom"
--monitorside = "top"
--monitor = peripheral.wrap("top")
startup()
Thanks for any help.Edited on 02 December 2014 - 11:23 PM