Jump to content




Title above main menu

lua

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

#1 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 12: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/>

Posted Image

#2 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 01: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!

#3 Fatal_Exception

  • New Members
  • 105 posts

Posted 17 October 2012 - 01: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

#4 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 01:04 PM

View PostDoyle3694, on 17 October 2012 - 01:02 PM, said:

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!

#5 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 01:05 PM

Nice to know I could help you!

#6 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 01:15 PM

View PostDoyle3694, on 17 October 2012 - 01:05 PM, said:

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.

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 October 2012 - 01:28 PM

You probably will have to use setCursorPos(x,y)

#8 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 01: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?

#9 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 01:34 PM

View PostDoyle3694, on 17 October 2012 - 01:30 PM, said:

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.

Posted Image

#10 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 October 2012 - 01:40 PM

View PostJuicyX, on 17 October 2012 - 01:34 PM, said:

View PostDoyle3694, on 17 October 2012 - 01:30 PM, said:

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.

Posted Image

Help with?

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

#11 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 01:43 PM

View PostsIdEkIcK_, on 17 October 2012 - 01:40 PM, said:

View PostJuicyX, on 17 October 2012 - 01:34 PM, said:

View PostDoyle3694, on 17 October 2012 - 01:30 PM, said:

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.

Posted Image

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


#12 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 01: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/>

#13 Ditto8353

  • New Members
  • 138 posts

Posted 17 October 2012 - 01:52 PM

View PostDoyle3694, on 17 October 2012 - 01:43 PM, said:

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.

#14 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 02: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.

#15 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 02:06 PM

View PostDoyle3694, on 17 October 2012 - 02:03 PM, said:

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 ^.^

#16 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 02: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

#17 JuicyX

  • New Members
  • 7 posts

Posted 17 October 2012 - 02:11 PM

View PostDoyle3694, on 17 October 2012 - 02:09 PM, said:

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/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users