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

Code for monitor?

Started by Formerform, 03 January 2014 - 05:31 PM
Formerform #1
Posted 03 January 2014 - 06:31 PM
Hi I have 2 programs that need to be run at the same time, one on the monitor and one on the computer. The monitor is just a
Print("Name of room")
and the one on the computer is a door lock. Is there a Lua code that i can put into my door lock code to run the "print" code on the monitor?
Imprivate #2
Posted 03 January 2014 - 08:47 PM
If I am understanding you correctly, you can do this:
You can write to a monitor by at the beginning of your code write:
monitor = peripheral.wrap("right")
replace "right" with whatever side of the computer your monitor is on (top, bottom, left or right).
Then, whenever you want to print to a monitor, instead write this:
monitor.write("YourText")

Note: If the above fixed your problem, ignore this:
If you want to run one program INSIDE of another program, use:
shell.run("ProgramName")
Replace "ProgramName" with the name of the program you want to run, in your case the 'print' program. If your new to Lua, maybe try starting out with something abit simpler?

Anyway, hope I helped :)/>
Edited on 03 January 2014 - 07:48 PM
sploders101 #3
Posted 03 January 2014 - 08:48 PM
lol I was typing an answer but he beat me to it :P/>

basically just do:


monitor=peripheral.wrap("top")
monitor.setCursorPos(1,1)
monitor.write("Name of room")
--your code here
Edited on 03 January 2014 - 07:50 PM
Imprivate #4
Posted 03 January 2014 - 08:49 PM
xD, Is that what you thought he meant? Just monitor.write? Or did he want to use shell.run?
theoriginalbit #5
Posted 03 January 2014 - 09:03 PM
xD, Is that what you thought he meant? Just monitor.write? Or did he want to use shell.run?
It is very clear that he wanted monitor.write
Formerform #6
Posted 15 January 2014 - 10:58 PM
If I am understanding you correctly, you can do this:
You can write to a monitor by at the beginning of your code write:
monitor = peripheral.wrap("right")
replace "right" with whatever side of the computer your monitor is on (top, bottom, left or right).
Then, whenever you want to print to a monitor, instead write this:
monitor.write("YourText")

Note: If the above fixed your problem, ignore this:
If you want to run one program INSIDE of another program, use:
shell.run("ProgramName")
Replace "ProgramName" with the name of the program you want to run, in your case the 'print' program. If your new to Lua, maybe try starting out with something abit simpler?

Anyway, hope I helped :)/>


Hey guys sorry for the late reply but Imprivate you have the answer I was looking for.

What I did was I needed the text to be in the center of the 2 monitors so what I did was I created 2 different programs the first one which "Startup" which had my password lock on my door and the second one was a program called "Monitor" which had this:

term.setCursorPos(4,3)
print("My Room")

and I used all the codes you guys told me to use and it worked. Thanks :D/>

Also do you guys know any programs that open an lua files that way I can just copy and paste my codes to make it easier for you guys. :)/>
theoriginalbit #7
Posted 15 January 2014 - 11:50 PM
Also do you guys know any programs that open an lua files that way I can just copy and paste my codes to make it easier for you guys. :)/>
well if you've got the HTTP API enabled you can always use the pastebin program. However the programs are always stored on the server machine, as plaintext… you can even edit the files in the following locations instead of in-game.

SSP
Windows
%APPDATA%\.minecraft\saves\[world name]\computer\[computer id]

Mac
~/Library/Application Support/minecraft/saves/[world name]/computer/[computer id]

Linux
~/.minecraft/saves/[world name]/computer/[computer id]
or
/home//.minecraft/saves/[world name]/computer/[computer id]

SMP
[server files]/[world name]/computer/[computer id]

making sure to substitute each appropriate value in where there appears a [] pair. If you do not know the ID of the computer type `id` into the computer and press enter.
Edited on 15 January 2014 - 10:50 PM
Formerform #8
Posted 19 January 2014 - 08:25 PM
well if you've got the HTTP API enabled you can always use the pastebin program. However the programs are always stored on the server machine, as plaintext… you can even edit the files in the following locations instead of in-game.

SSP
Windows
%APPDATA%\.minecraft\saves\[world name]\computer\[computer id]

Mac
~/Library/Application Support/minecraft/saves/[world name]/computer/[computer id]

Linux
~/.minecraft/saves/[world name]/computer/[computer id]
or
/home//.minecraft/saves/[world name]/computer/[computer id]

SMP
[server files]/[world name]/computer/[computer id]


making sure to substitute each appropriate value in where there appears a [] pair. If you do not know the ID of the computer type `id` into the computer and press enter.

I know where it is located but when I click on the file I want to edit it asks me which program do you want to open it up with, can I open it up with txt editor for example like notepad or Textedit.

And servers like pastebin work but I mean like offline wise.

Once again thanks for the support! :lol:/>
Lyqyd #9
Posted 19 January 2014 - 08:52 PM
Uh, yeah. Did you even try opening it in a text editor?