Jump to content




A quick guide through menu making


  • This topic is locked This topic is locked
42 replies to this topic

#21 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 06 August 2012 - 10:49 PM

Not sure if this is too improtant;

but this COULD be wrong, im not sure at all. Just posting this. If its not wrong, please tell me. I didnt know you could combine these...

term.clear() term.setCursorPos(1,1)


#22 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 08 August 2012 - 12:51 AM

This is great! I'm gonna try it now...

#23 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 16 August 2012 - 08:19 AM

here is a link to a basic menu generator I made a few days ago, turns out it didn't help the guy asking for help but you are welcome to use and adapt it

http://www.computerc...-advanced-menu/

please read to the end of the thread though so you can get the correct version

#24 ben657

  • Members
  • 65 posts

Posted 04 September 2012 - 06:11 AM

Nice useful code, but a quick suggestion, it's generally good practice to name your variables something meaningful. Just because you know what they are, doesn't mean other people do!

But still, very useful code!

#25 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 05 September 2012 - 06:05 AM

yeah, I've made a much better one since then though: runs better and can run in any area of the screen with customizable delimiters etc

http://pastebin.com/X9cC2MS3

#26 Creator13

  • New Members
  • 15 posts

Posted 15 September 2012 - 05:04 PM

I feel quite stupid asking this, but where do I put this part of the code
local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)
into this?
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
Because, when I put it just above it all, it gives an "attempt to call nil"-error at line
local n=CUI(options)


#27 Cricket

  • Members
  • 3 posts

Posted 15 September 2012 - 07:47 PM

View PostCreator13, on 15 September 2012 - 05:04 PM, said:

I feel quite stupid asking this, but where do I put this part of the code
local options={
"option1",
"option2",
"option3"
}
local n=CUI(options)
print(n)
into this?
function CUI(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a number[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
Because, when I put it just above it all, it gives an "attempt to call nil"-error at line
local n=CUI(options)
Put it below the function

#28 EmTeaKay

  • Members
  • 115 posts

Posted 15 September 2012 - 10:07 PM

How do I make a border for my menu? I tried asking in Ask a Pro forum section, and they said to come here.
Also, my options looke like this:
1
2
3
When I want them to look like this:
1 2 3
Any help?
Here's the code:
function clear()
term.clear()
term.setCursorPos(1,1)
end
function one()
sleep(.5)
clear()
print("Hello")
end
function two()
sleep(.5)
clear()
print("Hey")
end
function three()
sleep(.5)
clear()
print("Hi")
end
local menuOptions = {"1", "2", "3"}
local termX, termY = term.getSize()
local selected = 1
function centerText(text, termY)
term.setCursorPos(termX/2-#text/2,termY)
term.write(text)
return true
end
function start()
while true do
term.clear()
for i,v in ipairs(menuOptions) do
  if i == selected then
	   centerText("["..v.."]", i)
else
	centerText(v,i)
end
   end
   local id, key = os.pullEvent()
   if key == 208 and selected < #menuOptions then
	selected = selected + 1
   elseif key == 200 and selected > 1 then
	selected = selected - 1
   elseif key == 28 then
	return selected
   end
end
end
x = start()
print()
if selected == 1 then
one()
end
if selected == 2 then
two()
end
if selected == 3 then
three()
end


#29 Creator13

  • New Members
  • 15 posts

Posted 16 September 2012 - 08:19 AM

@EmTeaKay thanks, it works now.
I'm also trying to figure out how i get the options in one line. I didn't found any solutions yet...

#30 EmTeaKay

  • Members
  • 115 posts

Posted 16 September 2012 - 11:51 AM

Well, if you find a way to do it, would you please PM me how?

#31 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 18 September 2012 - 07:20 AM

I took a look at your code and made it put all the choices on the same line, it is still set to use the up and down arrow keys to navigate, that should be easy to change

http://pastebin.com/XCN2RHPf

#32 Mr. Fang

  • Members
  • 82 posts

Posted 21 September 2012 - 12:02 AM

Thank You this really helped a large amount! I'm rdy to make my Home CPU Now!

#33 Bansheebandit

  • New Members
  • 2 posts

Posted 24 October 2012 - 12:34 AM

Im trying to make a menu that highlights different options in my Nuclear Powerplants OS. Ive currently been using the simple menu that requests the user to type an option but think its time for an upgrade. Could you help me?

#34 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 24 October 2012 - 04:08 AM

sure, try making an option based menu like above, once you have that it is easy to upgrade. if you have problems let us know

#35 88theturbo

  • Members
  • 20 posts

Posted 28 March 2013 - 09:09 AM

Hmm. When I try to run it it says bios:337: [string "menu"] :17: 'then' expected
When I check it. there is a then... Can someone help?

#36 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 28 March 2013 - 09:25 AM

which code?

#37 88theturbo

  • Members
  • 20 posts

Posted 28 March 2013 - 10:15 AM

I used Cranium's Code, But I fixed it already. :) I didnt use the right amount of = signs in a part of the code. :D

#38 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 28 March 2013 - 10:19 AM

cool stuff, good luck to you sir

#39 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 31 March 2013 - 11:27 PM

View PostEspen, on 19 March 2012 - 12:00 AM, said:

View Postjtdavis99, on 18 March 2012 - 11:41 PM, said:

How did you know what codes were equivalent to the keys?
http://www.minecraft.../wiki/Key_Codes
You can also open up the lua prompt and do this
 while true do
     print(os.pullEvent())
 end
That's much quicker I think..

#40 DerDuden

  • Members
  • 4 posts

Posted 06 April 2013 - 11:18 AM

Thanks man really good work =)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users