←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

How Do I Make a Toggle menu

electronoah's Photo electronoah 13 Aug 2014

Hello there I am new to computercraft and want to make a simple menu.. I want a menu that can controle lights. But i want it to be able to toggle between if the lights are on or off... So the menu will have a list like so....

NUCLEAR FACTORY LIGHT CONTROL PAGE:1
OPERATIONS
*************************************************************

[1] Fence Lighting...........................[OFF]
[2] Main Hall Lighting.......................[OFF]
[3] Nuclear Development Room.......[OFF]
[4] Control Room Lights...................[OFF]
[5] Something Here Lights...............[OFF]
[6] You Get The Point......................[OFF]
[7] I Ran Out of Stuff........................[OFF]
[8] Nuclear Core Room....................[OFF]
Hit [SPACE] for next page


NUCLEAR FACTORY LIGHT CONTROL PAGE:1
OPERATIONS
*************************************************************

[1] Fence Lighting...........................[OFF]
[2] Main Hall Lighting.......................[ON]
[3] Nuclear Development Room.......[ON]
[4] Control Room Lights...................[ON]
[5] Something Here Lights...............[OFF]
[6] You Get The Point......................[OFF]
[7] I Ran Out of Stuff........................[OFF]
[8] Nuclear Core Room....................[ON]
Hit [SPACE] for next page

So i want to have each light able to be toggle... But with each option it has its own menu... Lets say i picked option [1] then this would pop up...

Fence Lighting Control Selected
_________________________

[1] Turn "Fence Lighting" OFF
[2] Turn "Fence Lighting" ON
[3] Check Status
[4] Return to Main Menu

So i can turn each light on or off and it will update it on the main menu, and i would also like to be able to mirror the main menu on a screen...

I would also like to be able to have the option i pick give me a little notification that i selected the right option.. like this

Fence Lighting Control Selected

_________________________

[1] Turn "Fence Lighting" OFF
[2] Turn "Fence Lighting" ON
[3] Check Status
[4] Return to Main Menu
Saving state of Fence Lighting
Fence Lighting ON

^^^^ and this will happen with each option like so....

Fence Lighting Control Selected

_________________________

[1] Turn "Fence Lighting" OFF
[2] Turn "Fence Lighting" ON
[3] Check Status
[4] Return to Main Menu
Saving state of Fence Lighting
Fence Lighting OFF


Fence Lighting Control Selected

_________________________

[1] Turn "Fence Lighting" OFF
[2] Turn "Fence Lighting" ON
[3] Check Status
[4] Return to Main Menu
Checking Status of "Fence Lighting"
Please Wait..........
Done


Fence Lighting Control Selected

_________________________

[1] Turn "Fence Lighting" OFF
[2] Turn "Fence Lighting" ON
[3] Check Status
[4] Return to Main Menu
Returning to Main Menu
Please Wait.........

My question is how do i make this and how do i make this work with bundle cable...
Edited by electronoah, 13 August 2014 - 06:03 PM.
Quote

Lyqyd's Photo Lyqyd 13 Aug 2014

Moved to Ask a Pro.
Quote

hilburn's Photo hilburn 13 Aug 2014

Hmmm well right off the bat, bundled cable doesn't really work at the moment, if you have Project Red (or equivalent) and Wireless Redstone I would suggest wrapping a transmitter and receiver as peripherals and using those. The system Would work something like this:

Previously set up: Receiver on Frequency (X) goes into a T flip flop, output of this goes to the lights and a transmitter on frequency (X+1)
Computer can find the status of the lights by setting it's receiver to frequency (X+1), can toggle the status of the lights by transmitting on X eg.

function TurnOn(freq)
    receiver.setFreq(freq+1) --#set receiver to the monitoring frequency
    if not rs.getInput("left") then --#if it's not on
         transmitter.setFreq(freq)  --#set transmitter to the toggle frequency
         rs.setOutput("back",true)
         sleep(0.1)
         rs.setOuptut("back",false) --#pulse the frequency to toggle the lights on
    end
end


As for the menu itself you could do use tables which would make it quite neat. Something like:
menu={[1]={menudisplay="Fence Lighting", selecttext="Fence Lighting Control Selected", submenu=
			{[1]={menudisplay="Turn Off", selecttext="Turning Fence Lighting Off", selectfunction=turnOff(1)},
			 [2]={menudisplay="Turn On", selecttext="Turning Fence Lighting On", selectfunction=turnOn(1),
             [3]=...}

You could then have a function called DisplayMenu which would do something like:

function DisplayMenu(dmenu)
    for i,j in pairs(dmenu) do
        print("["..i.."] "..j.menudisplay) --#prints out all the menu items of the table supplied to it
    end
    input=0
    while not (input>0 and input<=#menu) do   --#loops until valid input
        input=read()
    end
    print(dmenu[input].selecttext)            --#print out the confirmation text
    if dmenu[input].submenu then           --#if there is a submenu
        DisplayMenu(dmenu[input].submenu)  --#display it
    else                                                           --#otherwise
        dmenu[input].selectfunction                  --#do the function the menu item is tied to
    end
end
Quote

TheOddByte's Photo TheOddByte 13 Aug 2014

View Posthilburn, on 13 August 2014 - 06:28 PM, said:

Hmmm well right off the bat, bundled cable doesn't really work at the moment
That depends on which CC version he has, I believe bundled cables work until CC 1.6+
Quote

Cranium's Photo Cranium 13 Aug 2014

Well, to be more specific, they worked through MFR on CC 1.58. Bundled cable support was lost after Minecraft 1.4.7, due to Eloraam vanishing into the night.
Quote

electronoah's Photo electronoah 15 Aug 2014

I am on mine craft 1.6.4 so I am guessing bundle cable doesn't work.. I will get back to you when I get stuck.... Thanks for all your help..
Quote

Bomb Bloke's Photo Bomb Bloke 15 Aug 2014

Your version of MineCraft is not directly related to your version of ComputerCraft.
Quote