This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
exploder's profile picture

How to make computer automatically detect monitor side?

Started by exploder, 30 October 2012 - 01:54 PM
exploder #1
Posted 30 October 2012 - 02:54 PM
Hello.

I am trying to figure out how to make computer detect every side automatically without changing the side in code because every time I change my monitor side ex(left to right) I have to edit my startup file and change side manually.
remiX #2
Posted 30 October 2012 - 02:59 PM

tSides = {"left","right","bottom","top","front","back"}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
	side = tSides[i]
	break
  end
end

print(side)

Not sure this will work but I'm confident that it should :? Try it :P/>/>
KaoS #3
Posted 30 October 2012 - 02:59 PM

local side=nil
for k,v in pairs(rs.getSides()) do
  if peripheral.getType(v)=='monitor' then
    side=v
    break
  end
end
exploder #4
Posted 30 October 2012 - 03:11 PM

tSides = {"left","right","bottom","top","front","back"}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
	side = tSides[i]
	break
  end
end

print(side)

Not sure this will work but I'm confident that it should :? Try it :P/>/>

local side=nil
for k,v in pairs(rs.getSides()) do
  if peripheral.getType(v)=='monitor' then
	side=v
	break
  end
end

I can't seem to get both codes working but I bet that I'm just doing something wrong.

Here is the original code from my program that I'm trying to get working.


mon = peripheral.wrap("left") -- Here is the part where I'm trying to make computer auto-detect side for monitor.
term.redirect(mon) -- term.redirect(side) just gives me out an bios:32: error that is attempting to call nil.
term.clear()
term.setCursorPos(1,1)
while true do
local time = os.time()
time = textutils.formatTime(time, true)
print[[		
1.Access Computer.
2.Shutdown.
3.Leave a message.
4.Check messages.]]
term.setCursorPos(1,10) print("Computer ID:"..id.."") term.setCursorPos(26,10) print("Time "..time)
os.startTimer(0.5) event, param1, param2 = os.pullEvent() if event == "char" and param1 == "1" then access() elseif event == "char" and param1 == "2" then shutdown() elseif event == "char" and param1 == "3" then message() elseif event == "char" and param1 == "4" then checkm() break end
term.clear()
term.setCursorPos(1,1)
end


If I do this without term.redirect() then the program runs on terminal screen.
remiX #5
Posted 30 October 2012 - 04:18 PM

local side=nil
for k,v in pairs(rs.getSides()) do
  if peripheral.getType(v)=='monitor' then
	side=v
	break
  end
end

I use tekkit and apparently tekkit doesn't have getSides so didn't think of it :P/>/>

edit: I'll try the code and see if I can get it to work :P/>/>
KaoS #6
Posted 30 October 2012 - 04:19 PM

local side=nil
for k,v in pairs(rs.getSides()) do
  if peripheral.getType(v)=='monitor' then
   side=v
   break
  end
end
term.redirect(peripheral.wrap(side)) -- term.redirect(side) just gives me out an bios:32: error that is attempting to call nil.
term.clear()
term.setCursorPos(1,1)
while true do
  local time = os.time()
  time = textutils.formatTime(time, true)
  print('1.Access Computer.n2.Shutdown.n3.Leave a message.n4.Check messages.')
  term.setCursorPos(1,10)
  print("Computer ID:"..id.."")
  term.setCursorPos(26,10)
  print("Time "..time)
  os.startTimer(0.5)
  local event, param1, param2 = os.pullEvent()
  if event == "char" and param1 == "1" then
   access()
  elseif event == "char" and param1 == "2" then
   shutdown()
  elseif event == "char" and param1 == "3" then
   message()
  elseif event == "char" and param1 == "4" then
   checkm()
   break
  end
  term.clear()
  term.setCursorPos(1,1)
end
remiX #7
Posted 30 October 2012 - 04:31 PM
tSides = {"left","right","bottom","top","front","back"}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
		side = tSides[i]
		break
  end
end

This also works :P/>/> Just tested it but I see Kaos beat me into putting into your code.

Edit: To get all available sides:

tSides = {"left","right","bottom","top","front","back"}
tGetSides = {}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
	    table.insert(tGetSides, tSides[i])
  end
end

for i = 1, #tGetSides do
    print(tGetSides[i])
end
exploder #8
Posted 31 October 2012 - 05:23 PM

local side=nil
for k,v in pairs(rs.getSides()) do
  if peripheral.getType(v)=='monitor' then
   side=v
   break
  end
end
term.redirect(peripheral.wrap(side)) -- term.redirect(side) just gives me out an bios:32: error that is attempting to call nil.
term.clear()
term.setCursorPos(1,1)
while true do
  local time = os.time()
  time = textutils.formatTime(time, true)
  print('1.Access Computer.n2.Shutdown.n3.Leave a message.n4.Check messages.')
  term.setCursorPos(1,10)
  print("Computer ID:"..id.."")
  term.setCursorPos(26,10)
  print("Time "..time)
  os.startTimer(0.5)
  local event, param1, param2 = os.pullEvent()
  if event == "char" and param1 == "1" then
   access()
  elseif event == "char" and param1 == "2" then
   shutdown()
  elseif event == "char" and param1 == "3" then
   message()
  elseif event == "char" and param1 == "4" then
   checkm()
   break
  end
  term.clear()
  term.setCursorPos(1,1)
end

Thank you, this worked.


tSides = {"left","right","bottom","top","front","back"}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
		side = tSides[i]
		break
  end
end


This also works :P/>/> Just tested it but I see Kaos beat me into putting into your code.

Edit: To get all available sides:

tSides = {"left","right","bottom","top","front","back"}
tGetSides = {}

for i = 1, #tSides do
  monitor = peripheral.wrap(tSides[i])
  if monitor then
		table.insert(tGetSides, tSides[i])
  end
end

for i = 1, #tGetSides do
	print(tGetSides[i])
end

But thank you for helping as well. :P/>/>.