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

var gives 2.0 when written and not 2

Started by alonikomax, 24 March 2013 - 06:34 AM
alonikomax #1
Posted 24 March 2013 - 07:34 AM
why when i do this:
local mon = peripheral.wrap("back")
qnum = 1
qnum = qnum + 1
mon.setCursorPos(9, 6)
mon.write(qnum)
i get 2.0 on the screen and not 2?
i know that in c# you can do a num and not a normal var but i dont know to do that on lua.

thanks!

btw i need the answer fast plz.
faubiguy #2
Posted 24 March 2013 - 07:43 AM
You can format it into a single digit with string.format, like this
mon.write(string.format('%d', qnum))
MysticT #3
Posted 24 March 2013 - 08:04 AM
using tostring should work too:

mon.write(tostring(qnum))
alonikomax #4
Posted 24 March 2013 - 08:23 AM
worked! thanks.
MysticT's answer is shorter so i used that but thanks faubiguy :)/>