Jump to content




width and heigth


  • You cannot reply to this topic
7 replies to this topic

#1 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 22 September 2016 - 02:47 PM

couldn't there be some function added like term.getWidth and term.getHeigth, i know that there is term.getSize()

but it would be easier to do it like this
string.rep("-",term.getWidth)

than to do it like

w,h = term.getSize()
string.rep("-",w)

Edited by ReBraLaCC, 22 September 2016 - 02:48 PM.


#2 Lignum

  • Members
  • 558 posts

Posted 22 September 2016 - 03:05 PM

You can do this:
local width = ({term.getSize()})[1]
local height = ({term.getSize()})[2]
However, that's not a very pleasant solution.

Keep in mind that if you pass term.getSize() as an argument, that is the same as passing both of its return values consecutively. Therefore:
string.rep("-", term.getSize())
will work, because that's the same as doing:
string.rep("-", ({term.getSize()})[1], ({term.getSize()})[2]) --# third argument is ignored, since there's no parameter for it

Though I agree that the introduction of term.getWidth and term.getHeight would make code like this more readable.

#3 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 22 September 2016 - 03:20 PM

or you can do this

local width, height = term.getSize()
--# or
local width = term.getSize()
local _, height =  term.getSize()

Using these tricks you can make your own getWidth and getHeight functions. Also, if it's possible for the end user (us) to do then it usually won't be made by dan200

#4 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 22 September 2016 - 03:48 PM

Or of course:
local width = (term.getSize()) -- Limits it to one value to get width
local height = select(2, term.getSize()) -- Remove the 1st item in the vararg: so 51, 19 becomes 19.
Though separate methods would be nicer.

#5 ReBraLaCC

  • Members
  • 100 posts
  • LocationSublime Text 2

Posted 22 September 2016 - 05:15 PM

View PostLignum, on 22 September 2016 - 03:05 PM, said:

You can do this:
local width = ({term.getSize()})[1]
local height = ({term.getSize()})[2]

I tried todo that and it didnt work.... hmm (version 1.79pr3?)

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 22 September 2016 - 05:39 PM

That example should work on any version of Lua including LuaJ and any version of ComputerCraft. However, if you don't add the parenthesis it won't work.

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 September 2016 - 06:49 PM

Personally, I don't see much value in adding another two functions just to independently get information that's already available as the first and second return values of an existing function. Should we also add getCursorX and getCursorY?

#8 ebernerd

  • Members
  • 262 posts
  • LocationBoston, MA

Posted 22 September 2016 - 06:56 PM

View PostLyqyd, on 22 September 2016 - 06:49 PM, said:

Personally, I don't see much value in adding another two functions just to independently get information that's already available as the first and second return values of an existing function. Should we also add getCursorX and getCursorY?

I mean, I may be speaking from ignorance here, but isn't that more efficient if you're only looking for one value? Why have the program search for two values when you only want one?

Albeit, in CC the performance difference is literally nothing, so I don't see an immediate reason to add it





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users