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

Can You Correct My Code? Monitor Changer

Started by musicgack, 07 June 2012 - 10:51 PM
musicgack #1
Posted 08 June 2012 - 12:51 AM
This Is A Code To Make Monitors Wireless Can You correct It For Me?




Wireless Monitor Changer
*******************************
Server/Main PC:
=============================================
print("Wireless Monitor Editor By Musicgack")

rednet.open("back")

while true do
sleep(0.5)

monitortext = read()

rednet.broadcast(monitortext)
end
===============================================

PC With The Monitor ("Client")

===============================================
mon.write("This Software Is Made By Musicgack")
print("This Software Is Made By Musicgack")
sleep(5)
mon.clear()
term.clear()

rednet.open("back")

while true do
sleep(0.5)

id, msg = rednet.recieve()

monitortext = rednet.recieve()

mon.write(monitortext)

if msg = "clear" and id = "10" then
mon.clear()
end

if msg = "shutdown" and id = "10" then
mon.clear()
os.shutdown()
end

if msg = "font5" then
mon.setfontsize(5)
end

if msg = "font4" then
mon.setfontsize(4)
end

if msg = "font3" then
mon.setfontsize(3)
end

if msg = "font2" then
mon.setfontsize(2)
end

if msg = "font1" then
mon.setfontsize(1)
end

if msg = "nextline$" then
mon.nextline()
end

if msg = "restart" then
mon.setCursorPos(1,1)
end

if msg = "commands" then
mon.clear()
mon.setCursorPos(1,1)
mon.write("Commands")
mon.write("===========")
mon.write("font1 > font5 -Changes Font Size")
mon.write("clear -Clears The Monitor")
mon.write("nextline$ -Goes To The Next Line")
mon.write("shutdown -Shutdown The Computer")
mon.write("restart -Goes To 1st Line")
mon.write("Anything Else Will Go On The Screen")
mon.write("Clear The Screen Again =P")
end
end
=================================================
Bossman201 #2
Posted 08 June 2012 - 01:54 AM
You didn't tell us what your error was, or what you were doing when you got it.

Anyway, I know what it is. Remove "mon.write(monitortext)" from your code. Why did you code this in anyway? The variable monitortext is only used in one line of code. Change "mon.write(monitortext)" to "mon.write(msg)" and it'll work fine. There is also a better way to use an "if" statement by using "elseif" but I'll let you figure that one out. Also, remove the sleep statements and take out "and id = 10".

Last thing, when you are comparing two things with an "if" statement, you use 2 equals.

local x = 0

while x == 0 do
 if x == 0 then
  x = 1
 end
end
musicgack #3
Posted 26 June 2012 - 07:50 AM
I dont get that D=, and anyways can you test it?
Lyqyd #4
Posted 26 June 2012 - 06:47 PM
You can test your own code.

I also don't see anything setting up the monitor on the other computer. Is this the complete code?
Exerro #5
Posted 26 June 2012 - 07:29 PM
I don't have a clue about monitors or rednet but try putting mon.setFontSize(1,2,3,4,5) with the caps and if msg == whatever (you need 2 equal signs)