Jump to content




[Lua] Issues with monitor.write()


4 replies to this topic

#1 Salin

  • New Members
  • 2 posts

Posted 27 March 2013 - 11:36 AM

At the moment, I'm working on an elevator control turtle that will take touchscreen input. I plan to have it simply write floor numbers to the monitor, and have the player click the appropriate number. However, monitor.write() is behaving strangely. If I pass it an integer to write, in this case 5, it will return "5.0". Is there a way I can make it return simply "5", and as such avoid having to reposition the cursor and overwrite the decimal with whitespace?

Will post code shortly, Chrome has a tendency to crash on me.

Edit: Code:
m = peripheral.wrap("left") --Wrapping the monitor
w = peripheral.wrap("right") --Wrapping the REther module
local floor = 1 --Turtle starts at floor 1. Will play with filesystem so that I dont have to replace it every time the world loads
local floors= 5 --Highest Floor
local draw = 1
function drawing() --Relevant Code
m.setTextScale(2) --Just a bit easier to click
while draw <= floors do --Start the loop
m.setCursorPos((draw*2)-1,1) --Set the position - I want output in odd numbered positions only!
m.write(draw) --Assume draw is 5. This writes "5.0" to the monitor
write(draw) -- This outputs "5" to the console. How can I do this on the monitor?
--wait = read("*") -- Just for debug
draw = draw + 1 -- Advance the loop
end
draw = 1 -- Reset the variable so that this function can run again at the next floor
end
drawing()


#2 faubiguy

  • Members
  • 213 posts

Posted 27 March 2013 - 12:09 PM

If you pass the number to tostring first, like m.write(tostring(draw)), it will only write the '5'.

#3 Salin

  • New Members
  • 2 posts

Posted 27 March 2013 - 01:18 PM

Brilliant. Exactly what I needed - Thank you so much!

#4 Doyle3694

  • Members
  • 815 posts

Posted 27 March 2013 - 09:43 PM

If you have an further questions with monitor.write(), it might be of use to know that it acts exactly as term.write(), which is way more documented

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 27 March 2013 - 09:47 PM

personally I prefer to redirect the terminal to the monitor, that way you can use write and print functions which allow for delimited strings (i.e. \n \t etc)

example
Spoiler






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users