Jump to content




ZipMenu - Menus for your game

api

6 replies to this topic

#1 TheZipCreator

  • Members
  • 27 posts
  • LocationNew 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


Posted Image

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 by TheZipCreator, 12 November 2017 - 02:33 AM.


#2 Luca_S

  • Members
  • 407 posts
  • LocationGermany

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")


#3 TheZipCreator

  • Members
  • 27 posts
  • LocationNew York, US

Posted 12 November 2017 - 05:49 PM

View PostLuca_S, on 12 November 2017 - 12:18 PM, said:

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 by TheZipCreator, 12 November 2017 - 05:50 PM.


#4 Exerro

  • Members
  • 801 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.

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited 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.

#6 Exerro

  • Members
  • 801 posts

Posted 13 November 2017 - 04:45 PM

View PostKingofGamesYami, on 12 November 2017 - 10:47 PM, said:

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.

#7 Saldor010

  • Members
  • 467 posts
  • LocationThe 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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users