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

Formatting

Started by Brod8362, 29 March 2015 - 06:42 PM
Brod8362 #1
Posted 29 March 2015 - 08:42 PM
I was writing some programs for my pocket pc/terminal, with me writing the original files on the pocket pc. It looks weird on a normal terminal, and I wanted to know if there is a way to auto-format for what screen it is on. Thanks!
Spoiler
Geforce Fan #2
Posted 29 March 2015 - 08:56 PM
term.getSize() will return the width and height of the screen

if they're pocket computers, there will be a blank table called "pocket"
HPWebcamAble #3
Posted 29 March 2015 - 10:36 PM
Like Geforce Fan said, you can use term.getSize() to see how large the screen is:


w,h = term.getSize() --# w is the x axis, h is the y axis

Then, instead of using a set position (Like 'term.setCursorPos(3,4)'), use the width and height to position it (term.setCursorPos(w/2,h/2))


If you ever wanted to know what kind of computer is running your code, you can use this handy function:

local function getComputerType() --Handy function
  local ret = {}
  if term.isColor() then
    table.insert(ret, "advanced")
  end
  if pocket then
    table.insert(ret, "pda")
  elseif turtle then
    table.insert(ret, "turtle")
  else
    table.insert(ret, "computer")
  end
  return table.concat(ret, "_")
end

For example, on a regular pocket computer, it would return 'pda'
On an advanced turtle, it would return 'advanced_turtle'
Edited on 29 March 2015 - 08:39 PM