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

Menuysys

Started by Metalhead33, 06 November 2016 - 10:10 PM
Metalhead33 #1
Posted 06 November 2016 - 11:10 PM
Hello everyone, this is my first post on the forum, although I am a long-time lurker :)/>

I would like to show everyone my Menusys API. What does it do? It gives us an easy way to create interactive menus, that's what it does!

The actual code can be found here:
http://pastebin.com/hWNaWTz6
It depends on this other API that I created:
http://pastebin.com/ShiTjX9W

To install them, you need to run:

pastebin get ShiTjX9W corefunc
pastebin get hWNaWTz6 menusys

Alternatively, just download this script by doing:

pastebin get nCmA6FJa update-menusys

Okay, but how exactly does my menusys thing get used?
What you need to do is to declare a table full of choices, and run a loop that displays the menu until the desired result is given.
For example:

os.loadAPI("menusys")
function A() print("Chocie 1") end

function B() print("Chocie 2") end

function C() print("Chocie 3") end
tbl = { "1", "2", "3" }
while true do
  local x = menusys.displayMenu(tbl,"This is the intro of the test function","This is the outro of the test function",1)
  if x == 0 then
	exit()
   elseif x == 1 then
	 A()
   elseif x == 2 then
	 B()
   elseif x == 3 then
	 C()
  end

end

What exactly happened there? Well, it called the display displayMenu function, and returns the position you were on before you pressed ENTER. Then you can decide what to do depending on the position.
A demonstration with multi-dimensional menus can be found here.

I am also working on an ImageDisplayer library.
Also available for OpenComputers.

Copyright © 2016, Zsolt Tóth

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Edited on 07 November 2016 - 06:25 PM
Mao Zedong #2
Posted 19 November 2016 - 09:17 PM
Could you show screenshots? :D/>