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

How Do I Make a Toggle menu

Started by electronoah, 13 August 2014 - 04:56 AM
electronoah #1
Posted 13 August 2014 - 06:56 AM
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 on 13 August 2014 - 05:03 PM
Lyqyd #2
Posted 13 August 2014 - 03:58 PM
Moved to Ask a Pro.
hilburn #3
Posted 13 August 2014 - 07:28 PM
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
TheOddByte #4
Posted 13 August 2014 - 08:33 PM
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+
Cranium #5
Posted 13 August 2014 - 10:42 PM
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.
electronoah #6
Posted 15 August 2014 - 02:28 PM
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..
Bomb Bloke #7
Posted 15 August 2014 - 05:15 PM
Your version of MineCraft is not directly related to your version of ComputerCraft.