Metalhead33 0 Posted November 7, 2016 Share Posted November 7, 2016 Hello everyone! This is my very first post on the forum, and ho-boy, have I got some software library for you guys.MenuSys. So what exactly does MenuSys does, and why am I bragging about it like it's some great invention?Well, because it's not great invention at all. Quite the contrary. It is something anyone could have came up with, and in fact, it's entirely possible that someone has already created something similar, and I was just simply too lazy to check.But okay, okay, enough bad jokes.MenuSys basically gives programmers an easy way to implement menus by giving them an API that lets them define a bunch of menu options in a table, call the menu, and have a conditional branch based on what did they choose. The best way to get MenuSys is via pastebin, although you'll net an InternetCard in your computer for that. pastebin get 41g8zs6R menusys.lua Put it somewhere you will find easily... like /lib or /usr/lib.So how to use it?First, you need to local menusys = require("menusys") Then you'll need a table. If you use only one dimension, you will call on the function displayMenu. If you use a two-dimensional array, you'll gonna use displayMenuMult. Here is some demonstration with single-dimension tables: local menusys = require("menusys") local choices = { "1", "2", "3" } while true do local x = menusys.displayMenu(choices,"Intro","Outro",1) if x == 0 then break end end Do note that Intro and Outro can be either text or function. Why function? Because that way, you can do graphical things before the menu is displayed. And with two-dimension tables:Here is some demonstration with single-dimension tables: local menusys = require("menusys") choice_state = { [1] = { false, false }, [2] = { false, false }, } function choice_concat(text,x,y) if choice_state[x][y] == true then return text .. " " .. x .. "-" .. y .. " [ON]" else return text .. " " .. x .. "-" .. y .. " [OFF]" end end choices = { } for xkey,xvalue in ipairs(choice_state) do choices[xkey] = { } for ykey,yvalue in ipairs(xvalue) do choices[xkey][ykey] = function() return choice_concat("NODE",xkey,ykey) end end end x = 1 y = 1 while true do x,y = menusys.displayMenuMult(choices,"Test Functions","Test Functions",x,y) if x == 0 then exit() else if choice_state[x][y] == true then choice_state[x][y] = false else choice_state[x][y] = true end end end It is also available for ComputerCraft. MIT License ----------- Copyright © 2016, Zsolt TóthPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE. Quote Link to post Share on other sites
Aether 1 Posted May 17, 2017 Share Posted May 17, 2017 I would like to know how can a choice call a function because I was trying this and I didn't find out, I'm talking about the single dimension table. Quote Link to post Share on other sites