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

Welcome Monitor

Started by xXFirefox205Xx, 16 November 2014 - 01:26 PM
xXFirefox205Xx #1
Posted 16 November 2014 - 02:26 PM
Hello there, I'm kinda new to ComputerCraft, so I created a small program that types out words like a sign at a gas station or a convenience store. I know this is very basic and probably has a lot of kinks that need to be sorted out, so please, let me know.
No Pastebin just yet, ill get one soon

while true do
local mon = peripheral.wrap("monitor_1")

mon.clear()
mon.setCursorPos(1,1)
mon.setTextScale(4)
sleep(0.5)
mon.write("W")
sleep(0.5)
mon.write("e")
sleep(0.5)
mon.write("l")
sleep(0.5)
mon.write("c")
sleep(0.5)
mon.write("o")
sleep(0.5)
mon.write("m")
sleep(0.5)
mon.write("e")
mon.setCursorPos("1.2")
sleep(0.5)
mon.write("P")
sleep(0.5)
mon.write("l")
sleep(0.5)
mon.write("a")
sleep(0.5)
mon.write("y")
sleep(0.5)
mon.write("e")
sleep(0.5)
mon.write("r")
sleep("1.5")
KingofGamesYami #2
Posted 17 November 2014 - 12:35 AM
Tip: code tags!
your code here

Another tip: forum safe comments


--I'm a normal lua comment!
print( "this line looks terrible!" )
--let's stop it here
--#I'm a valid lua comment, and detectable by the forum
print( "much nicer" )

That being said, I can offer some improvements to you code, if you like. I'm not saying your code is bad, just that it could be improved.
theoriginalbit #3
Posted 17 November 2014 - 01:01 AM
It may interest you to take a look at http://computercraft.info/wiki/Textutils.slowPrint
xXFirefox205Xx #4
Posted 17 November 2014 - 01:36 AM
haha I could've used the .slowprint code *faceplam*
Edited on 17 November 2014 - 12:45 AM
xXFirefox205Xx #5
Posted 17 November 2014 - 01:39 AM
Tip: code tags!
your code here

Another tip: forum safe comments


--I'm a normal lua comment!
print( "this line looks terrible!" )
--let's stop it here
--#I'm a valid lua comment, and detectable by the forum
print( "much nicer" )

That being said, I can offer some improvements to you code, if you like. I'm not saying your code is bad, just that it could be improved.
I'll take code improvements
Edited on 17 November 2014 - 12:47 AM
KingofGamesYami #6
Posted 17 November 2014 - 02:17 PM
-snip-
I'll take code improvements

Ok. Firstly, what you have doesn't allow the end user to edit it very much, so let's fix that.

local mon
for _, name in ipairs( peripheral.getNames() ) do --#iterate through all attached peripherals
  if peripheral.getType( name ) == "monitor" then --#find a monitor
     mon = peripheral.wrap( name ) --#set the monitor
     break --#exit the loop
  end
end

Next, we can use a loop and string.sub to easily add anything you like


local str = "This is anything you want"
for i = 1, #str do
  mon.write( string.sub( str, i, i ) )
  sleep( 0.5 )
end

I'll leave it here for now. (school's starting for me)

EDIT: Fixed thing dragon pointed out (*facedesk*)
Edited on 17 November 2014 - 06:46 PM
Dragon53535 #7
Posted 17 November 2014 - 07:02 PM
-snip-
I'll take code improvements

Ok. Firstly, what you have doesn't allow the end user to edit it very much, so let's fix that.

local mon
for _, name in ipairs( peripheral.getNames() ) do --#iterate through all attached peripherals
  if peripheral.getType( name ) == "monitor" then --#find a monitor
	 mon = name --#set the monitor
	 break --#exit the loop
  end
end
Ahem, you're forgetting to wrap the peripheral.
KingofGamesYami #8
Posted 17 November 2014 - 07:42 PM
-snip-
Ahem, you're forgetting to wrap the peripheral.
EDIT: I'm stupid… Thanks for pointing that out.
Edited on 17 November 2014 - 06:46 PM
xXFirefox205Xx #9
Posted 19 November 2014 - 12:28 AM
-snip-
Ahem, you're forgetting to wrap the peripheral.
EDIT: I'm stupid… Thanks for pointing that out.
so whats the code supposed to do?
KingofGamesYami #10
Posted 19 November 2014 - 03:25 PM
-snip-
so whats the code supposed to do?

The first bit finds a monitor, rather than forcing the user to specify one.

The second bit is the equivalent of this:

sleep(0.5)
mon.write("W")
sleep(0.5)
mon.write("e")
sleep(0.5)
mon.write("l")
sleep(0.5)
mon.write("c")
sleep(0.5)
mon.write("o")
sleep(0.5)
mon.write("m")
sleep(0.5)
mon.write("e")
mon.setCursorPos("1.2")
sleep(0.5)
mon.write("P")
sleep(0.5)
mon.write("l")
sleep(0.5)
mon.write("a")
sleep(0.5)
mon.write("y")
sleep(0.5)
mon.write("e")
sleep(0.5)
mon.write("r")
…but allowing the user to add any string they want.
xXFirefox205Xx #11
Posted 19 November 2014 - 07:47 PM
so the entire code would be…
srry, im such a noob