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

A better menu tutorial

Started by Zudo, 20 January 2013 - 04:51 AM
Zudo #1
Posted 20 January 2013 - 05:51 AM
Arrow key menus are hard to make.
Here is how to make one (easy-medium difficulty)

Example 1

function myMenu() -- Define menu
opt = 1 -- Set the selected option to 1
while true do -- Begin loop
 term.clear()
 term.setCursorPos(1,1)
  if opt == 1 then -- If yes selected?
   print("YES no")
  else -- Its not
   print("yes NO")
  end
  e, a, b = os.pullEvent("key") -- Get key
  if a == 203 and opt > 0 then -- If key is left arrow and OPT is larger than 0?
   opt = 1 -- Set option to 1
  elseif a == 205 and opt < 2 then -- If key is right arrow and OPT is smaller than 2?
   opt = 2 -- Set option to 2
  elseif a == keys.enter then -- RETURN hit?
   break -- Break out of loop
  end
return opt -- Return selected
end

yn = myMenu() -- Call myMenu and save returned param to yn
if yn == 1 then -- If yes selected?
print("YES!")
else -- Not selected?
print("NO!")
end

This will make a simple yes/no menu. Feel free to modify the print()s to what you like.

Will be making a more advanced tutorial soon!
InputUsername #2
Posted 20 January 2013 - 08:23 AM
Quite simple and basic and cool :)/>

One thing you might add is a term.clear() and term.setCursorPos(1,1) before printing the options.

Because when running the function now, it will do something like this:

> YES no
> yes NO
> YES no

In other words, it will move a line down after selecting and print the new 'state' of the menu.

Good example for beginners though :)/>

By the way, I gave you an internet :P/>
TheOddByte #3
Posted 20 January 2013 - 09:59 AM
Quite simple and basic and cool :)/>

One thing you might add is a term.clear() and term.setCursorPos(1,1) before printing the options.

Because when running the function now, it will do something like this:

> YES no
> yes NO
> YES no

In other words, it will move a line down after selecting and print the new 'state' of the menu.

Good example for beginners though :)/>

By the way, I gave you an internet :P/>
Well…
I gave you both an internet :P/>
InputUsername #4
Posted 20 January 2013 - 11:37 PM
Well…
I gave you both an internet :P/>

Thanks :D/>
Zudo #5
Posted 21 January 2013 - 01:19 AM
Quite simple and basic and cool :)/>

One thing you might add is a term.clear() and term.setCursorPos(1,1) before printing the options.

Because when running the function now, it will do something like this:

> YES no
> yes NO
> YES no

In other words, it will move a line down after selecting and print the new 'state' of the menu.

Good example for beginners though :)/>

By the way, I gave you an internet :P/>

I forgot :)/>