Jump to content




Is there a way to set where a new line starts?


3 replies to this topic

#1 Spexiono

  • Members
  • 14 posts

Posted 21 February 2014 - 04:10 AM

Hey,

Is there a way to set where the new line starts whenever i use the print() command?
At the moment i have this:
term.setCursorPos(17,7)
print("+------------------+")
term.setCursorPos(17,8)
print("|				  |")
term.setCursorPos(17,9)
print("+------------------+")
to produce a box like this:

Posted Image
(Edit: Formatting didn't work so i made a screen shot, How do you force a post to show multiple spaces?)

Is there a better way to set where the new line starts so i don't have to essentially repeat term.setCursorPos(17,x)

I can't do this:
print("				 +------------------+")
print("				 |                  |")
print("				 +------------------+")

Because this replaces any text to the left of the box with spaces which overwrites other parts of my program.

Edited by Spexiono, 21 February 2014 - 04:19 AM.


#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

Posted 21 February 2014 - 04:44 AM

You can write your own print function but you should use term.write instead of print because you don't really need line wrapping. There's no other way of doing it, you'll have to set the cursor every time you write. What you could do is put your GUI into a table and then use a for loop to draw each row stored in a table.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 21 February 2014 - 05:38 AM

A (basic) example of such a function:

local function indentPrint(text)
	local curx,cury = term.getCursorPos()
	term.write(text)
	term.setCursorPos(curx,cury+1)
end

With this in place, you'd then re-write the rest of your script to just:

term.setCursorPos(17,7)
indentPrint("+------------------+")
indentPrint("|                  |")
indentPrint("+------------------+")


#4 Spexiono

  • Members
  • 14 posts

Posted 22 February 2014 - 06:12 PM

View PostBomb Bloke, on 21 February 2014 - 05:38 AM, said:

local function indentPrint(text)
	local curx,cury = term.getCursorPos()
	term.write(text)
	term.setCursorPos(curx,cury+1)
end
Thanks, this has worked perfectly, :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users