27 posts
Location
New York, US
Posted 12 November 2017 - 02:33 AM
ZipMenu
Hello, and yes this time I do have a pastebin for this, I made a thing where you can create custom menus.Note:You need two programs for this to work, one to open the menu, and another to be a callback to receive the input from the menu. So, to download
pastebin get qh3T84pJ
The code to create the image above is as follows:In a file called "Menu":
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
shell.run("zipMenu", "My_menu", "callback", "Item1", "Item2", "Item3")
In a file called "Callback":
local params = {...}
print("You chose ".. params[1])
Edited on 12 November 2017 - 01:33 AM
477 posts
Location
Germany
Posted 12 November 2017 - 12:18 PM
Instead of using shell.run() you should probably make this as an API and just return the number, so you can invoke it like this:
os.loadAPI("zipmenu")
local chosen = zipmenu.menu("My_menu", "Item1", "Item2", "Item3")
27 posts
Location
New York, US
Posted 12 November 2017 - 05:49 PM
Instead of using shell.run() you should probably make this as an API and just return the number, so you can invoke it like this:
os.loadAPI("zipmenu")
local chosen = zipmenu.menu("My_menu", "Item1", "Item2", "Item3")
Yeah I'll do that. But instead of returning a number, it will return a string, which is the name of the item you chose. Just to make the code easier to read.
Edited on 12 November 2017 - 04:50 PM
797 posts
Posted 12 November 2017 - 10:23 PM
A number is good for if you have multiple options with the same text (for whatever reason). Alternatively, you could return the text and the number as a second parameter.
3057 posts
Location
United States of America
Posted 12 November 2017 - 10:47 PM
I return text in my own implementation of this, I don't think multiple options with the same text that do different things should ever exist. It would be confusing for the user.
797 posts
Posted 13 November 2017 - 04:45 PM
I return text in my own implementation of this, I don't think multiple options with the same text that do different things should ever exist. It would be confusing for the user.
I had an issue with just text before with a file-browser, where it trimmed the extension and displayed that separately. Files with the same name but different extensions would have the same name returned when clicked. Not so much of a problem here I guess, but the more information the better imo.
598 posts
Location
The United States
Posted 13 November 2017 - 05:35 PM
Can't you have a check when you create a button that automatically renames the button's internal name to something like buttonName_1,2,3 etc if you have a naming conflict like that?