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

Confirm Box / Normal Box / Scrollable Text box functions

Started by remiX, 10 February 2013 - 12:56 AM
remiX #1
Posted 10 February 2013 - 01:56 AM
So I made this for my new ComputerCraft YouTube program and thought I may as well post it here as it's quite handy, imo.

The functions can be found here

Usage Example (confirmBox and drawBox functions):

How it works:
borderCol  = colour of the outside border
boxCol	 = colour of the inside of the box
headingCol = colour of the heading that appears at the top of the box
textCol	= colour of the text that appears within the box
xStart	 = starting X position of the box (top left hand corner of the box)
xEnd	   = ending X position of the box (top right hand corner of the box)
yStart	 = starting Y positon of the box (top line)
...		= arguments, accepts as many as you want. First one is the title.

The height of the box is determined by how many strings you give it.

Spoiler
os.loadAPI("box")
screenX, screenY = term.getSize()

-- Draw a confirm box
term.clear()
opt = box.confirmBox(colours.grey, colours.lightGrey, colours.red, colours.white, 5, screenX - 5, 6, "Confirm", "Are you sure you want to", "delete the file?", "thisFile")
term.clear()
term.setCursorPos(1, 1)
print(opt)
if opt == "YES" then
	-- Yes let's delete the file
else
	-- Why not?
end

sleep(1)
-- Draw a normal box with text
term.clear()
box.drawBox(colours.grey, colours.lightGrey, colours.red, colours.white, 5, screenX - 5, 6, "", "This is a test and can be", "considered as the most useless", "information. But it's just a test!") -- Use "" as the first string if you don't want it to have a heading

Usage Example (textBox function):
(This box allows as much text as you need - supports scroll!)

How it works:
--[[
	 boxCol = colour of the entire box
	 textCol = colour of the text inside of the box area
	 xStart = starting X position of the box
	 xEnd = ending X position of the box
	 yStart = starting Y position of the box
	 yEnd = ending Y position of the box
	 tText = Can be a string OR a table
	 
	 String:
		- Use '\n' to separate lines.
	 Table:
		- Make sure lines are WELL spaced for the area
		  of the box or else it will fail!
--]]

Spoiler
msg = "New update!\n\nWhat's new:\n - Feature 1\n - Feature 2\n - Feature 3\n - Feature 4\n - Feature 5\n\nDownload:\nwww.pastebin/code\n\n\nFeedback and suggestions are welcome!"
tab = {
	"New update!",
	"",
	"What's new:",
	" - Feature 1",
	" - Feature 2",
	" - Feature 3",
	" - Feature 4",
	" - Feature 5",
	"Download:",
	"www.pastebin/code",
	"", "",
	"Feedback and suggestions are welcome!"
}
screenX, screenY = term.getSize()

os.loadAPI("box")

term.setBackgroundColour(colours.black)
term.clear()
term.setCursorPos(1, 1)

box.textBox(colours.lightGrey, colours.red, 2, screenX - 2, 3, 10, msg) -- or use tab for the table
Getalife #2
Posted 10 February 2013 - 04:45 AM
Nice functions :D/>
remiX #3
Posted 10 February 2013 - 05:59 AM
Thanks :P/> Took a few minutes to make them
Dave-ee Jones #4
Posted 15 May 2013 - 04:34 AM
Now this is usefulness. Nice. Reminds me of GameMaker GML Message box scripting…
Engineer #5
Posted 26 May 2013 - 07:48 PM
This is pretty nice man! Also, very usefull!