Jump to content




var gives 2.0 when written and not 2

lua computer

3 replies to this topic

#1 alonikomax

  • Members
  • 14 posts

Posted 24 March 2013 - 07:34 AM

why when i do this:

Quote

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.

#2 faubiguy

  • Members
  • 213 posts

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))


#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 24 March 2013 - 08:04 AM

using tostring should work too:
mon.write(tostring(qnum))


#4 alonikomax

  • Members
  • 14 posts

Posted 24 March 2013 - 08:23 AM

worked! thanks.
MysticT's answer is shorter so i used that but thanks faubiguy :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users