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

Title above main menu

Started by JuicyX, 17 October 2012 - 11:55 AM
JuicyX #1
Posted 17 October 2012 - 01:55 PM
http://pastebin.com/RbK5sSE4

That is my program(credit to rondouglas) and I was wondering how to add a title above the menu.

In the picture below, above Open Stairs I wish to have a title but I can't figure out how to do it.
Thank you to whoever can help! :D/>/>

Doyle3694 #2
Posted 17 October 2012 - 02:02 PM
in

function main()
		while running do
				term.clear()
				term.setCursorPos(1,1) -- added
				print(title) --added
				term.setCursorPos(1,2)
				printMenu(mainMenu)
				event, key = os.pullEvent("key")
				onKeyPressed(key, mainMenu)
		end
end

Marked the added lines. then at the top you can assign a variable to the string you want and voila!
Fatal_Exception #3
Posted 17 October 2012 - 02:02 PM

...snip...
--[[ Main Methods ]]--
function main()
  while running do
	term.clear()
	term.setCursorPos(1,1)	-- << These two lines
	print("Your Title Here")  -- <<  
	term.setCursorPos(1,2)
	printMenu(mainMenu)
	event, key = os.pullEvent("key")
	onKeyPressed(key, mainMenu)
  end
end

edit: sneaky ninjas in the shadows
JuicyX #4
Posted 17 October 2012 - 02:04 PM
in

function main()
		while running do
				term.clear()
				term.setCursorPos(1,1) -- added
				print(title) --added
				term.setCursorPos(1,2)
				printMenu(mainMenu)
				event, key = os.pullEvent("key")
				onKeyPressed(key, mainMenu)
		end
end

Marked the added lines. then at the top you can assign a variable to the string you want and voila!

Wow, I tried a bunch of things and never got it and now realise how simple it was, thank you!
Doyle3694 #5
Posted 17 October 2012 - 02:05 PM
Nice to know I could help you!
JuicyX #6
Posted 17 October 2012 - 02:15 PM
Nice to know I could help you!

Just one more thing, how would I center the menu and add another line of text on the other side of the screen from the title?
I found out how to center just text but I can't seem to get it working with the menu.
remiX #7
Posted 17 October 2012 - 02:28 PM
You probably will have to use setCursorPos(x,y)
Doyle3694 #8
Posted 17 October 2012 - 02:30 PM
I don't think I followed the turns there, what exactly are you trying to do? Make another text on the other side but at the same line as the title?
JuicyX #9
Posted 17 October 2012 - 02:34 PM
I don't think I followed the turns there, what exactly are you trying to do? Make another text on the other side but at the same line as the title?

I figured out how to center the menu but I still need help with this.

remiX #10
Posted 17 October 2012 - 02:40 PM
I don't think I followed the turns there, what exactly are you trying to do? Make another text on the other side but at the same line as the title?

I figured out how to center the menu but I still need help with this.


Help with?

Btw, did you center with term.setCursorPos() or another way, if another way, how do you do it? :D/>/>
JuicyX #11
Posted 17 October 2012 - 02:43 PM
I don't think I followed the turns there, what exactly are you trying to do? Make another text on the other side but at the same line as the title?

I figured out how to center the menu but I still need help with this.


Help with?

Btw, did you center with term.setCursorPos() or another way, if another way, how do you do it? :D/>/>

Where it says "TEXT HERE!@" in the picture I wish to do it in computercraft.

and I found this function on google lol and I just added it to where the script prints the menu.


local cPrint = function(text)
	    local x2,y2 = term.getCursorPos()
	    local x,y = term.getSize()
	    term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
	   
	    print(text)
end

function printMenu(menu)
for i = 1, #menu do
  if i == selectedItem then
   cPrint("[ "..menu[i].text.." ]")
  else
   cPrint(""..menu[i].text)
  end
end
end
Doyle3694 #12
Posted 17 October 2012 - 02:43 PM
I got it now, think I know how to do it:

function printEnd(text, y)
x = 49-#text
term.setCursorPos(x,y)
write(text)
end
Is my basic idea. going to go test some stuff with it now.

EDIT: It works! :D/>/>
Ditto8353 #13
Posted 17 October 2012 - 02:52 PM
I got it now, think I know how to do it:

function printEnd(text, y)
x = 49-#text
term.setCursorPos(x,y)
write(text)
end
Is my basic idea. going to go test some stuff with it now.

EDIT: It works! :D/>/>

instead of a constant 49, use x = term.getSize() - #text
Note that getSize() returns x and y, but the y is ignored since it has nowhere to put it.
Doyle3694 #14
Posted 17 October 2012 - 03:03 PM
no because this is for a computer and a computer can have 51 characters on 1 line. this is the eaisets and msot simple way to do it. gives 3 blanksteps free space too.
JuicyX #15
Posted 17 October 2012 - 03:06 PM
no because this is for a computer and a computer can have 51 characters on 1 line. this is the eaisets and msot simple way to do it. gives 3 blanksteps free space too.

I'm still having trouble adding that into the program ^.^
Doyle3694 #16
Posted 17 October 2012 - 03:09 PM
just add this function at the top or something, and then call the function after the 2 lines we added before, with the y as 1 and text as whatever you want to print there
JuicyX #17
Posted 17 October 2012 - 03:11 PM
just add this function at the top or something, and then call the function after the 2 lines we added before, with the y as 1 and text as whatever you want to print there

Oh, I got it. Thanks again! :D/>/>