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

Write to monitor, Remove decimal place on numbers?

Started by FailedFace, 07 March 2014 - 10:23 AM
FailedFace #1
Posted 07 March 2014 - 11:23 AM
So I have a program that acts as a message board and anyone can come up to add a message to it. More simply I have a problem with the write function.
If I issue m.write(i) and i = 1, or another integer, the monitor shows up with 1.0 or 2.0 etc.
Is there some way to use the write function that doesn't change # into #.0?

From what I understand is that the write function is for peripherals, and the print function is for the terminal.

Thanks in advance for any help, please don't get upset if a topic exists with this already. I don't think I missed it, but there is always that chance.
Lyqyd #2
Posted 07 March 2014 - 03:29 PM
mon.write(tostring(num)) should do it. You can use print on monitors, you simply need to redirect the terminal to the monitor using term.redirect first. Check out the term API page on the wiki for usage.
FailedFace #3
Posted 10 March 2014 - 02:23 AM
I had tried tostring before but realized the problem was me changing the cursor position to 0,0 instead of 1,1 after a monitor clear which made me think this was failing >_<. Thanks, for making me look into this further.
Also, why is it that it starts at 1,1 and not 0,0 if 0,0 doesn't return an out of range index error?
Also, with reguard to the redirect method for terminal, which is pretty sweet, what object do I pass to redirect back to the terminal(stop redirecting), without a reboot?
Thanks for all your help.

I found term.restore(), nvm about the term.redirect question. :)/>/>
GopherAtl #4
Posted 10 March 2014 - 06:44 PM
term.restore() will undo a term.redirect() call.

As of the 1.6 beta, which isn't in full release yet, restore is removed. Instead, you do something like "oldTerm=term.redirect(monitor) <do stuff> term.redirect(oldTerm)" or, in a pinch, term.redirect(term.native())