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

Nuclear Reactor Setup For Dummies (and I'm a dummy...) HELP!

Started by wowplayer101, 05 July 2012 - 03:31 AM
wowplayer101 #1
Posted 05 July 2012 - 05:31 AM
Hey guys, I just started using computercraft with Tekkit on my server, and I'm trying to set up a nuclear reactor interface so you have multiple paths you can choose- whether to continue, turn on reactor, cool reactor, ETC. I have my central computer set so that to even access the mainframe, you need to enter a password.

The problem I'm having is that I can't figure out the programming for a multiple choice system.
I have something as follows:

print ("Welcome to The Nuclear Reactor Mainframe!")
print ()
print ("Please select an action to take.")
print ("1. Reactor Menu")
print ("2. Early Warning Systems")
print ("3. Manual Shutdown")
print ("4. Cancel")

input = read()
if input == "1" then
term.clear()
term.setCursorPos(1,1)
print (" Reactor Menu ")
print ()
print ("1. Start Reactor")
print ("2. Start Cooling Systems")
print ("3. Begin Timer Until Uranium Refill Required") –I'm making the refill of uranium manual, so there are no "accidents"
print ("4. Cancel")
input = read()
if input == "1" then
term.clear()
term.setCursorPos(1,1)
print ("Accessing Files…")
sleep(2)
print ()
print ("Starting Reactor…")
sleep(2)
redstone.setOutput("back", true) –I have a NOT gate setup, so this will turn the reactor on (will run continously without a redstone signal)
print ()
print ("Reactor Successfully Started")

Now here's the part I need help with. I want the program to return to the Nuclear Reactor Menu, not the mainframe menu or the startup password entry. The only way I've learned to program this is to type os.shutdown() to shut down the computer and then restart, but then you'd have to navigate there again. If someone could:
A: Help me with the return function of my programming (to the previous page)
and B: Either proofread my programming or tell me how to do this…

The program should look something like this

startup –> Enter Password –> type in Nuclear Reactor –> Display Reactor Mainframe Choices
1. Reactor Menu
2. Early Warning Systems
3. Emergancy Shutdown
4. Cancel

1. Should Entail:
Starting the Reactor
Stopping the Reactor
Starting the Cooling Systems (just needs to power pistons to let water flow in)
Stopping Cooling Systems
Start Timer Until Next Uranium Refill
and the all important: Cancel
2 Should just have:
Starting the Sirens
Stopping the Sirens (Manually; the sirens will automatically go off at 4500 degree heat)
3 Needs another redstone output, just to activate pistons, destroying redstone circuitry, turning off reactor
4 another cancel

Also, would there be any way for me to display this all on the monitor I have above the computer?
I have no disk drives or anything like that, so all sides are open for redstone except top and front.
(as if i haven't asked enough =P) Would there also be a way for the program to automatically check for a redstone output on one side (idc which) so if the overheating gets too bad, it can pull up a screen on the monitor asking if you want to shut off the reactor or not? (it can use the same output as the one to manually turn on-off reactor in order to shut the reactor off)

Thanks to anyone who even looks at this post. I know it's quite wordy, and takes a while to get through. I would greatly appreciate help on this here =P Remember, I'm new to this (2 days, in fact)
so I won't understand much of lua or programming language.

Thanks, thanks, and thanks again!
Lyqyd #2
Posted 05 July 2012 - 05:43 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.
HelenB #3
Posted 05 July 2012 - 06:40 AM
OMG I came here because I googled for a script like this but couldn't find one. I'm wonder if I can have a copy of this script when it's finished.
wowplayer101 #4
Posted 05 July 2012 - 07:49 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry about the double copy post… I forgot to add this title (which was what I wanted in the first place) after I had already posted the other one. :P/>/>

Thanks for the info, I understood most of it. ^_^/>/>

I have some questions, however, just basic understanding things. :D/>/>

– e, p = os.pullEvent() – what does this string mean? I don't understand the os.pullEvent(), does it pull up the sub-menus?
– if e == char then – This would mean that if the input is "true" (or equal to) the character in the menu, then preform this action, correct?
– if p == someChar then – and lastly, I do not understand this line of code =( What is this mysterious p variable. The E would be my equivelant to input = read(), – then – if input == (code) then (do whatever), but what is this p? Is it simply another variable or version of Input (password, code, etc.)?

The last code has the same questions in it, exept for this one line:
–elseif p == subMenuKey then – Once again with that darn p. If p is just another input term (as I am assuming for now, until
– subMenu() – conformation) then this code is saying (in continuation of elseif) that if the key/character typed is the submenu key, then it pulls up the submenu? –!! I really don't understand that last bit about the subMenu() !!– :)/>/>

Thanks once more for enduring the drudgery of this post. This information did really help, though, and for that I thank you.

As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. ;)/>/>
wowplayer101 #5
Posted 05 July 2012 - 08:10 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry to post again, but late-night befuddled, hazy thinking has set in again, and I forgot to ask a couple questions.

I would like the last bit (the part about successfully starting the reactor) to automatically return to the reactor menu. Is there any way I can do this without having to press a button, or would it just be best to manually return? The way I look at it would be:

Its a loop inside a loop inside a loop inside a loop.

Reactor Mainframe –> Reactor Menu –> Choice of starting reactor or cancelling (wooh, only 2 choices here!) –> either manually returning to reactor menu (skipping the start reactor yes-no option) or automatically doing it. Would it be possible to just skip the start reactor screen entirely and go back to the reactor menu, cutting out the middle man?

On a completely unrelated note, the bottom coding (in your post) would be for the overall menu (or heirchy, if you like)? Where the coding says if this is a submenu key, then I would plug in the submenu coding, or the top coding, correct? If I needed a sub-menu inside a submenu, i would just plug in that keying again, correct?

Thanks for all the help you've shown. This is truly amazing, and I am extremely grateful for any help I can get.
HelenB #6
Posted 05 July 2012 - 01:45 PM
As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. :P/>/>

Aww thankies! :)/>/>
How have you hooked up your computer system to your power plant? Could I have a screenshot and explaination on how you did it?
Deathknight0897 #7
Posted 05 July 2012 - 01:55 PM
I have a question why don't you get the cc sensor then you can read temperature as well and implement an emergency overheat protocol that would shut down the plant you could also make bulk head doors close and so on much suggested considering nuclear power capabilities to destroy everything
HelenB #8
Posted 05 July 2012 - 02:45 PM
I have a question why don't you get the cc sensor then you can read temperature as well and implement an emergency overheat protocol that would shut down the plant you could also make bulk head doors close and so on much suggested considering nuclear power capabilities to destroy everything

That wasn't a question but a suggestion. lol
wowplayer101 #9
Posted 05 July 2012 - 08:34 PM
Well, I'm a dipstick. After some night's sleep and a clear head, I was looking back over my previous posts and realized I had answered my own question about the submenu. :P/>/>

Thanks for the info, and as for the blast doors, I will be having something like that, and I will be using the temperature gauges to trip redstone. I have a Colored Light system set up (I'm using tekkit, so I have redpower) and Blue= Off/ stationary, dark green = very cool, light green= cool, yellow = rising temperatures, starts to trigger emergancy procedures, orange is overheating, triggers sirens and pulls up warning display, red = all sirens activate, emergancy doors close, secure the room. flashing red = iminant meltdown, and even if you can't stop it, it will have a blast sheild containing reinforced stone (harder than obsidion) obsidion, RS, obsidion, steel, obsidion, and iron. all of these layers have emergancy blast doors. Sound safe enough? :)/>/>
HelenB #10
Posted 06 July 2012 - 12:55 AM
Well, I'm a dipstick. After some night's sleep and a clear head, I was looking back over my previous posts and realized I had answered my own question about the submenu. :P/>/>

Thanks for the info, and as for the blast doors, I will be having something like that, and I will be using the temperature gauges to trip redstone. I have a Colored Light system set up (I'm using tekkit, so I have redpower) and Blue= Off/ stationary, dark green = very cool, light green= cool, yellow = rising temperatures, starts to trigger emergancy procedures, orange is overheating, triggers sirens and pulls up warning display, red = all sirens activate, emergancy doors close, secure the room. flashing red = iminant meltdown, and even if you can't stop it, it will have a blast sheild containing reinforced stone (harder than obsidion) obsidion, RS, obsidion, steel, obsidion, and iron. all of these layers have emergancy blast doors. Sound safe enough? :)/>/>

You should create a secondary power plant well out of site for testing purposes and put this setup inside it then cause a meltdown and see how it goes. :D/>/>

You should place a big massive monitor in the control room that will display live status of the plant on it. I'm planning on it.
Lyqyd #11
Posted 06 July 2012 - 01:16 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry about the double copy post… I forgot to add this title (which was what I wanted in the first place) after I had already posted the other one. :P/>/>

Thanks for the info, I understood most of it. ^_^/>/>

I have some questions, however, just basic understanding things. :D/>/>

– e, p = os.pullEvent() – what does this string mean? I don't understand the os.pullEvent(), does it pull up the sub-menus?
– if e == char then – This would mean that if the input is "true" (or equal to) the character in the menu, then preform this action, correct?
– if p == someChar then – and lastly, I do not understand this line of code =( What is this mysterious p variable. The E would be my equivelant to input = read(), – then – if input == (code) then (do whatever), but what is this p? Is it simply another variable or version of Input (password, code, etc.)?

The last code has the same questions in it, exept for this one line:
–elseif p == subMenuKey then – Once again with that darn p. If p is just another input term (as I am assuming for now, until
– subMenu() – conformation) then this code is saying (in continuation of elseif) that if the key/character typed is the submenu key, then it pulls up the submenu? –!! I really don't understand that last bit about the subMenu() !!– :)/>/>

Thanks once more for enduring the drudgery of this post. This information did really help, though, and for that I thank you.

As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. ;)/>/>

os.pullEvent() takes an event off of the event queue. Events are generated each time a key on the keyboard is pressed, redstone inputs change, a rednet message is received, and a few other things happen. read() actually uses this function and uses the events from pressing keys on the keyboard to create a string, which then gets returned after the user presses enter. In the use here, we are getting an event type "e" and the first parameter "p" from whatever it returns. You could call these anything you like. So here's our example event pull call:


e, p = os.pullEvent()

Now, when we reach that line, the computer will wait for an event to be triggered. Let's say we press the G key at that point. The function will return two values: a string naming the event type ("char" in this case) and the character we typed ("g" in this example). So, our next two lines were:


if e == "char" then
		if p == "g" then

As you can see, I've modified the psuedocode to match what we're doing in this example. 'e', the event type, is checked to determine whether we are dealing with a character or not ("char"). If we are, we want to find out which character was typed. So, we check the parameter ('p') to see if it was the "g" key that was pressed.

Now, the subMenu() line. Each submenu you want to use would be placed in its own function. See how the first block of psuedocode starts with "local function …"? That's a function declaration. In our example, if we push the button for the submenu, the program will call the submenu function for whichever submenu we want (you'll need to set this up with a function for each submenu and call each one based on which key was pressed in the main menu). The function will clear the screen and draw the submenu options, then use the os.pullEvent() sequence just like the main menu, except that it will have its own actions for each key pressed. Once you are done with the submenu, you can simply use return to exit the submenu. If all of your menus are in loops, once the function returns, the main menu will clear the screen and draw itself again.

So to summarize, each menu you want should have a similar form:
  • Clear the screen
  • Draw the menu
  • Pull events
  • Act on chosen events
Each menu should also be in its own function. The main menu will call each submenu function when the submenu should be displayed, and each submenu will 'return' to exit back to the main menu. Each menu should also be contained in a 'while true do' loop so that it will continue to pull events until valid input is received.
wowplayer101 #12
Posted 06 July 2012 - 04:28 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry about the double copy post… I forgot to add this title (which was what I wanted in the first place) after I had already posted the other one. :P/>/>

Thanks for the info, I understood most of it. ^_^/>/>

I have some questions, however, just basic understanding things. :D/>/>

– e, p = os.pullEvent() – what does this string mean? I don't understand the os.pullEvent(), does it pull up the sub-menus?
– if e == char then – This would mean that if the input is "true" (or equal to) the character in the menu, then preform this action, correct?
– if p == someChar then – and lastly, I do not understand this line of code =( What is this mysterious p variable. The E would be my equivelant to input = read(), – then – if input == (code) then (do whatever), but what is this p? Is it simply another variable or version of Input (password, code, etc.)?

The last code has the same questions in it, exept for this one line:
–elseif p == subMenuKey then – Once again with that darn p. If p is just another input term (as I am assuming for now, until
– subMenu() – conformation) then this code is saying (in continuation of elseif) that if the key/character typed is the submenu key, then it pulls up the submenu? –!! I really don't understand that last bit about the subMenu() !!– :)/>/>

Thanks once more for enduring the drudgery of this post. This information did really help, though, and for that I thank you.

As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. ;)/>/>

os.pullEvent() takes an event off of the event queue. Events are generated each time a key on the keyboard is pressed, redstone inputs change, a rednet message is received, and a few other things happen. read() actually uses this function and uses the events from pressing keys on the keyboard to create a string, which then gets returned after the user presses enter. In the use here, we are getting an event type "e" and the first parameter "p" from whatever it returns. You could call these anything you like. So here's our example event pull call:


e, p = os.pullEvent()

Now, when we reach that line, the computer will wait for an event to be triggered. Let's say we press the G key at that point. The function will return two values: a string naming the event type ("char" in this case) and the character we typed ("g" in this example). So, our next two lines were:


if e == "char" then
		if p == "g" then

As you can see, I've modified the psuedocode to match what we're doing in this example. 'e', the event type, is checked to determine whether we are dealing with a character or not ("char"). If we are, we want to find out which character was typed. So, we check the parameter ('p') to see if it was the "g" key that was pressed.

Now, the subMenu() line. Each submenu you want to use would be placed in its own function. See how the first block of psuedocode starts with "local function …"? That's a function declaration. In our example, if we push the button for the submenu, the program will call the submenu function for whichever submenu we want (you'll need to set this up with a function for each submenu and call each one based on which key was pressed in the main menu). The function will clear the screen and draw the submenu options, then use the os.pullEvent() sequence just like the main menu, except that it will have its own actions for each key pressed. Once you are done with the submenu, you can simply use return to exit the submenu. If all of your menus are in loops, once the function returns, the main menu will clear the screen and draw itself again.

So to summarize, each menu you want should have a similar form:
  • Clear the screen
  • Draw the menu
  • Pull events
  • Act on chosen events
Each menu should also be in its own function. The main menu will call each submenu function when the submenu should be displayed, and each submenu will 'return' to exit back to the main menu. Each menu should also be contained in a 'while true do' loop so that it will continue to pull events until valid input is received.

So if I just type Return after i want to go back a menu, it will return me? no funky os.'s or ()'s?
wowplayer101 #13
Posted 06 July 2012 - 04:58 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry about the double copy post… I forgot to add this title (which was what I wanted in the first place) after I had already posted the other one. :P/>/>

Thanks for the info, I understood most of it. ^_^/>/>

I have some questions, however, just basic understanding things. :D/>/>

– e, p = os.pullEvent() – what does this string mean? I don't understand the os.pullEvent(), does it pull up the sub-menus?
– if e == char then – This would mean that if the input is "true" (or equal to) the character in the menu, then preform this action, correct?
– if p == someChar then – and lastly, I do not understand this line of code =( What is this mysterious p variable. The E would be my equivelant to input = read(), – then – if input == (code) then (do whatever), but what is this p? Is it simply another variable or version of Input (password, code, etc.)?

The last code has the same questions in it, exept for this one line:
–elseif p == subMenuKey then – Once again with that darn p. If p is just another input term (as I am assuming for now, until
– subMenu() – conformation) then this code is saying (in continuation of elseif) that if the key/character typed is the submenu key, then it pulls up the submenu? –!! I really don't understand that last bit about the subMenu() !!– :)/>/>

Thanks once more for enduring the drudgery of this post. This information did really help, though, and for that I thank you.

As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. ;)/>/>

os.pullEvent() takes an event off of the event queue. Events are generated each time a key on the keyboard is pressed, redstone inputs change, a rednet message is received, and a few other things happen. read() actually uses this function and uses the events from pressing keys on the keyboard to create a string, which then gets returned after the user presses enter. In the use here, we are getting an event type "e" and the first parameter "p" from whatever it returns. You could call these anything you like. So here's our example event pull call:


e, p = os.pullEvent()

Now, when we reach that line, the computer will wait for an event to be triggered. Let's say we press the G key at that point. The function will return two values: a string naming the event type ("char" in this case) and the character we typed ("g" in this example). So, our next two lines were:


if e == "char" then
		if p == "g" then

As you can see, I've modified the psuedocode to match what we're doing in this example. 'e', the event type, is checked to determine whether we are dealing with a character or not ("char"). If we are, we want to find out which character was typed. So, we check the parameter ('p') to see if it was the "g" key that was pressed.

Now, the subMenu() line. Each submenu you want to use would be placed in its own function. See how the first block of psuedocode starts with "local function …"? That's a function declaration. In our example, if we push the button for the submenu, the program will call the submenu function for whichever submenu we want (you'll need to set this up with a function for each submenu and call each one based on which key was pressed in the main menu). The function will clear the screen and draw the submenu options, then use the os.pullEvent() sequence just like the main menu, except that it will have its own actions for each key pressed. Once you are done with the submenu, you can simply use return to exit the submenu. If all of your menus are in loops, once the function returns, the main menu will clear the screen and draw itself again.

So to summarize, each menu you want should have a similar form:
  • Clear the screen
  • Draw the menu
  • Pull events
  • Act on chosen events
Each menu should also be in its own function. The main menu will call each submenu function when the submenu should be displayed, and each submenu will 'return' to exit back to the main menu. Each menu should also be contained in a 'while true do' loop so that it will continue to pull events until valid input is received.

Also, I have another question. I have my main menu, then my reactor menu, and then a sequence for starting the Reactor. This in turn needs to automatically return to the Reactor menu (before it) Do i need to put that in a loop, or can I just type "Return" at the bottom of the sequence to bring up the Reactor Menu again?
wowplayer101 #14
Posted 06 July 2012 - 05:42 AM
For the menu, you're going to want to put each submenu in its own function, each in an infinite loop. Each of these submenu functions clears the screen, draws the menu, and accepts input to choose the options. When exiting the menu and returning to the menu above, the function returns. Then the parent menu will loop back around and re-draw itself. Here's the psuedocode I wrote up the last time I answered this sort of question:


local function subMenu()
	while true do
		clearTheScreen()
		printTheSubMenu()
		e, p = os.pullEvent()
		if e == char then
			if p == someChar then
				performAction()
			elseif p == goBackChar then
				return
			end
		end
	end
end

while true do
	clearTheScreen()
	printTheMenu()
	e, p = os.pullEvent()
	if e == char then
		if p == someKey then
			doSomeStuff()
		elseif p == subMenuKey then
		   subMenu()
		elseif p == exitChar then
			return
		else
			whineAboutInvalidOption()
		end
	end
end

As far as the monitor usage goes, check the Peripheral API as well as the numerous tutorials and other posts inquiring about monitor usage. With the overheating pulling up a special menu: you'll be pulling events anyway for the menus (instead of using read(), if you use the method I suggested above), so just handle the redstone events appropriately.

Feel free to ask for clarification on any of this.

Sorry about the double copy post… I forgot to add this title (which was what I wanted in the first place) after I had already posted the other one. :P/>/>

Thanks for the info, I understood most of it. ^_^/>/>

I have some questions, however, just basic understanding things. :D/>/>

– e, p = os.pullEvent() – what does this string mean? I don't understand the os.pullEvent(), does it pull up the sub-menus?
– if e == char then – This would mean that if the input is "true" (or equal to) the character in the menu, then preform this action, correct?
– if p == someChar then – and lastly, I do not understand this line of code =( What is this mysterious p variable. The E would be my equivelant to input = read(), – then – if input == (code) then (do whatever), but what is this p? Is it simply another variable or version of Input (password, code, etc.)?

The last code has the same questions in it, exept for this one line:
–elseif p == subMenuKey then – Once again with that darn p. If p is just another input term (as I am assuming for now, until
– subMenu() – conformation) then this code is saying (in continuation of elseif) that if the key/character typed is the submenu key, then it pulls up the submenu? –!! I really don't understand that last bit about the subMenu() !!– :)/>/>

Thanks once more for enduring the drudgery of this post. This information did really help, though, and for that I thank you.

As for HelenB, yes, you may certainly have my copy of the program, once I struggle through it and debug the whole thing. ;)/>/>

os.pullEvent() takes an event off of the event queue. Events are generated each time a key on the keyboard is pressed, redstone inputs change, a rednet message is received, and a few other things happen. read() actually uses this function and uses the events from pressing keys on the keyboard to create a string, which then gets returned after the user presses enter. In the use here, we are getting an event type "e" and the first parameter "p" from whatever it returns. You could call these anything you like. So here's our example event pull call:


e, p = os.pullEvent()

Now, when we reach that line, the computer will wait for an event to be triggered. Let's say we press the G key at that point. The function will return two values: a string naming the event type ("char" in this case) and the character we typed ("g" in this example). So, our next two lines were:


if e == "char" then
		if p == "g" then

As you can see, I've modified the psuedocode to match what we're doing in this example. 'e', the event type, is checked to determine whether we are dealing with a character or not ("char"). If we are, we want to find out which character was typed. So, we check the parameter ('p') to see if it was the "g" key that was pressed.

Now, the subMenu() line. Each submenu you want to use would be placed in its own function. See how the first block of psuedocode starts with "local function …"? That's a function declaration. In our example, if we push the button for the submenu, the program will call the submenu function for whichever submenu we want (you'll need to set this up with a function for each submenu and call each one based on which key was pressed in the main menu). The function will clear the screen and draw the submenu options, then use the os.pullEvent() sequence just like the main menu, except that it will have its own actions for each key pressed. Once you are done with the submenu, you can simply use return to exit the submenu. If all of your menus are in loops, once the function returns, the main menu will clear the screen and draw itself again.

So to summarize, each menu you want should have a similar form:
  • Clear the screen
  • Draw the menu
  • Pull events
  • Act on chosen events
Each menu should also be in its own function. The main menu will call each submenu function when the submenu should be displayed, and each submenu will 'return' to exit back to the main menu. Each menu should also be contained in a 'while true do' loop so that it will continue to pull events until valid input is received.

Also, I keep having this weird error code, saying that the "end" on my last line needs to end the function of the submenu (on line one).
Help!
Lyqyd #15
Posted 06 July 2012 - 05:48 AM
Please copy and paste the code you have written so far. It will be much easier to help you.
wowplayer101 #16
Posted 06 July 2012 - 04:19 PM
Please copy and paste the code you have written so far. It will be much easier to help you.
Errr… I've been typing this in in-game, and I can't find it in my server files =( (I'm using this on a server)

Is there a way to copy the code in-game?
Lyqyd #17
Posted 06 July 2012 - 06:19 PM
Go to the server files, look in the world directory. There should be a "computer" folder. The program will be in one of the individual computer folders in there.
wowplayer101 #18
Posted 06 July 2012 - 06:30 PM
Go to the server files, look in the world directory. There should be a "computer" folder. The program will be in one of the individual computer folders in there.
Maahh, I can't find the world directory… I went to Mods, then CC, then where? I'v looked in all the folders, but it appears I can't find it. I'll keep looking, and if (thats a big if) I find it, it shall be posted!

Go to the server files, look in the world directory. There should be a "computer" folder. The program will be in one of the individual computer folders in there.
(This is a tekkit server, btw, don't know if it makes a difference)
MysticT #19
Posted 06 July 2012 - 06:32 PM
It's not inside the mod folder, it's in the world save folder.
Lyqyd #20
Posted 06 July 2012 - 06:32 PM
Not the mods folder, the world folder. Where all the chunk files live. There's a computer folder inside there.
wowplayer101 #21
Posted 06 July 2012 - 07:04 PM
Not the mods folder, the world folder. Where all the chunk files live. There's a computer folder inside there.
I went to my world folder, here is what is in here:
data folder (empty)
EnderStorage(empty)
players: Contains dat files on Nomad_Novix, litlpaul, and WoWplayer101 (me)
RedstoneEther: filled with .dat files (fmap, fprop, gprop, node1 and node2)
region: r.0.0.mca, r.0.1.mca, so forth and so on
level.dat DAT file
level.dat_old DAT_OLD file
railcraft.dat
session.lock, and
uid.dat

Thassit… The only file related to CC is in my mods (what I previously posted) :P/>/>
wowplayer101 #22
Posted 06 July 2012 - 07:08 PM
Thanks for all the help, everyone. Sorry I'm asking so many questions, I really don't know much about my server (didn't realize how much I didn't know until now =()

Thanks to all of you who have bared through these comments, just to try and help me! :P/>/>
wowplayer101 #23
Posted 06 July 2012 - 08:42 PM
Go to the server files, look in the world directory. There should be a "computer" folder. The program will be in one of the individual computer folders in there.

Disregard that post about it not working, I got it fixed. Now I'm having trouble with the Reactor-menu sub-menu…. When I try to take action (press a number to start reactor, for instance) it wont work. Period. Do I need to have ANOTHER sub-menu in there? All I want it to do is print some stuff, sleep, then turn on redstone behind it and return to the reactor menu. I guess I'd need to set that up as a loop, but does that mean I need 4 more sub menu's just to preform that function as well as stopping the reactor, starting the timer and returning?
Lyqyd #24
Posted 07 July 2012 - 01:17 AM
I really can't guess at what's not working correctly without seeing the current code, sorry.
wowplayer101 #25
Posted 07 July 2012 - 04:45 AM
I really can't guess at what's not working correctly without seeing the current code, sorry.

I FOUND IT!!!

Apparently, I have 2 tekkit servers, one of which I thought had the world I was playing in. WRONG! I found the coding!

local function subMenu()

while true do

term.clear()

term.setCursorPos(1,1)

print ()

print ("**************************************************")

print ()

print (" Reactor Menu")

print ()

print ("1. Start Reactor")

print ("2. Start Refill Timer")

print ("3. Stop Reactor")

print ("4. Back")

e, p = os.pullEvent()

if e == char then

if p == "1" then

while true do

term.clear()

term.setCursorPos(1,1)

print ("Loading Mainframe…")

sleep(3)

print ()

print ("Loading Subsystems…")

sleep(2)

print()

print ("Starting Reactor…")

sleep(2)

redstone.setOutput("back", true)

sleep(2)

print ()

print (" Reactor Successfully Started")

return

end

elseif p == "2" then

term.clear()

term.setCursorPos(1,1)

print ("Starting Timer…")

redstone.setOutput("left", true)

sleep(2)

return

elseif p == "3" then

print ("Stopping Reactor…")

sleep(4)

rs.setOutput("back", false)

sleep(2)

print ("Reactor Stopped.")

sleep(2)

return

elseif p == "4" then

return

end

end

end
end


– Variables go here
x = 1
y = 2
z = 5
r = (x + y)
s = (y + z)
t = (x + z)

–Beginning of Code

while true do

term.clear()

term.setCursorPos(1,1)

print ()
print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")

print ("————————————————–")

print ()


print (" Welcome to the Nuclear Reactor Mainframe!")
print ()

print ("Please Choose an Action")

print ("1. Reactor Menu")
print ("2. Early Warning Systems")
print ("3. Emergancy Shutdown")

print ("4. Cooldown Settings")

e, p = os.pullEvent()

if p == "1" then

subMenu()

elseif p == "2" then

print ("hi")

end
end
end
– I haven't actually finished this part here, just made a filler so I could test the program.

When I test the program, I can access the submenu (good) but I can't access any of the submenu's functions (bad).

Hope this helps!
Thanks!
Lyqyd #26
Posted 07 July 2012 - 05:28 AM
Okay, I've revised the code and added comments where I made changes.


--renamed function to better describe which submenu it is.
local function reactorMenu()
	while true do
		term.clear()
		term.setCursorPos(1,1)
		print ()
		print ("**************************************************")
		print ()
		print (" Reactor Menu")
		print ()
		print ("1. Start Reactor")
		print ("2. Start Refill Timer")
		print ("3. Stop Reactor")
		print ("4. Back")
		e, p = os.pullEvent()
		--char is a string, so we need quotes around it.
		if e == "char" then
			if p == "1" then
				-we do not need a while true do here since we return immediately at the end of the sequence.
				term.clear()
				term.setCursorPos(1,1)
				print ("Loading Mainframe...")
				sleep(3)
				print ()
				print ("Loading Subsystems...")
				sleep(2)
				print()
				print ("Starting Reactor...")
				sleep(2)
				redstone.setOutput("back", true)
				sleep(2)
				print ()
				print (" Reactor Successfully Started")
			elseif p == "2" then
				term.clear()
				term.setCursorPos(1,1)
				print ("Starting Timer...")
				redstone.setOutput("left", true)
				sleep(2)
				return
			elseif p == "3" then
				print ("Stopping Reactor...")
				sleep(4)
				rs.setOutput("back", false)
				sleep(2)
				print ("Reactor Stopped.")
				sleep(2)
				return
			elseif p == "4" then
				return
			end
		end
	end
end


-- Variables go here
x = 1
y = 2
z = 5
r = (x + y)
s = (y + z)
t = (x + z)

--Beginning of Code

while true do
	term.clear()
	term.setCursorPos(1,1)
	print ()
	print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
	print ("--------------------------------------------------")
	print ()
	print (" Welcome to the Nuclear Reactor Mainframe!")
	print ()
	print ("Please Choose an Action")
	print ("1. Reactor Menu")
	print ("2. Early Warning Systems")
	print ("3. Emergency Shutdown")
	print ("4. Cooldown Settings")
	e, p = os.pullEvent()
	--make sure we are handling a char event before checking the parameter.
	if e == "char" then
		if p == "1" then
			reactorMenu()
		elseif p == "2" then
			print ("hi")
		end
	end
end
wowplayer101 #27
Posted 07 July 2012 - 06:39 AM
Okay, I've revised the code and added comments where I made changes.


--renamed function to better describe which submenu it is.
local function reactorMenu()
	while true do
		term.clear()
		term.setCursorPos(1,1)
		print ()
		print ("**************************************************")
		print ()
		print (" Reactor Menu")
		print ()
		print ("1. Start Reactor")
		print ("2. Start Refill Timer")
		print ("3. Stop Reactor")
		print ("4. Back")
		e, p = os.pullEvent()
		--char is a string, so we need quotes around it.
		if e == "char" then
			if p == "1" then
				-we do not need a while true do here since we return immediately at the end of the sequence.
				term.clear()
				term.setCursorPos(1,1)
				print ("Loading Mainframe...")
				sleep(3)
				print ()
				print ("Loading Subsystems...")
				sleep(2)
				print()
				print ("Starting Reactor...")
				sleep(2)
				redstone.setOutput("back", true)
				sleep(2)
				print ()
				print (" Reactor Successfully Started")
			elseif p == "2" then
				term.clear()
				term.setCursorPos(1,1)
				print ("Starting Timer...")
				redstone.setOutput("left", true)
				sleep(2)
				return
			elseif p == "3" then
				print ("Stopping Reactor...")
				sleep(4)
				rs.setOutput("back", false)
				sleep(2)
				print ("Reactor Stopped.")
				sleep(2)
				return
			elseif p == "4" then
				return
			end
		end
	end
end


-- Variables go here
x = 1
y = 2
z = 5
r = (x + y)
s = (y + z)
t = (x + z)

--Beginning of Code

while true do
	term.clear()
	term.setCursorPos(1,1)
	print ()
	print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
	print ("--------------------------------------------------")
	print ()
	print (" Welcome to the Nuclear Reactor Mainframe!")
	print ()
	print ("Please Choose an Action")
	print ("1. Reactor Menu")
	print ("2. Early Warning Systems")
	print ("3. Emergency Shutdown")
	print ("4. Cooldown Settings")
	e, p = os.pullEvent()
	--make sure we are handling a char event before checking the parameter.
	if e == "char" then
		if p == "1" then
			reactorMenu()
		elseif p == "2" then
			print ("hi")
		end
	end
end

Ok, wow, I cannot thank you enough, man. This thing is lookin' pretty sweet, all thanks to you. I now have it working properly, and the rest won't be hard.

I am truly grateful! Thank you SOOOOO much, man!

@HelenB: I plan on finishing the scripting tomorrow, haven't tested the programming to it's full extent but have tested failsafes, and they seem to be working. I'll work hard to get the finished product out tomorrow!

THANK YOU SOOOO MUCH
to everyone who helped!
HelenB #28
Posted 22 July 2012 - 04:43 PM
Okay, I've revised the code and added comments where I made changes.


--renamed function to better describe which submenu it is.
local function reactorMenu()
	while true do
		term.clear()
		term.setCursorPos(1,1)
		print ()
		print ("**************************************************")
		print ()
		print (" Reactor Menu")
		print ()
		print ("1. Start Reactor")
		print ("2. Start Refill Timer")
		print ("3. Stop Reactor")
		print ("4. Back")
		e, p = os.pullEvent()
		--char is a string, so we need quotes around it.
		if e == "char" then
			if p == "1" then
				-we do not need a while true do here since we return immediately at the end of the sequence.
				term.clear()
				term.setCursorPos(1,1)
				print ("Loading Mainframe...")
				sleep(3)
				print ()
				print ("Loading Subsystems...")
				sleep(2)
				print()
				print ("Starting Reactor...")
				sleep(2)
				redstone.setOutput("back", true)
				sleep(2)
				print ()
				print (" Reactor Successfully Started")
			elseif p == "2" then
				term.clear()
				term.setCursorPos(1,1)
				print ("Starting Timer...")
				redstone.setOutput("left", true)
				sleep(2)
				return
			elseif p == "3" then
				print ("Stopping Reactor...")
				sleep(4)
				rs.setOutput("back", false)
				sleep(2)
				print ("Reactor Stopped.")
				sleep(2)
				return
			elseif p == "4" then
				return
			end
		end
	end
end


-- Variables go here
x = 1
y = 2
z = 5
r = (x + y)
s = (y + z)
t = (x + z)

--Beginning of Code

while true do
	term.clear()
	term.setCursorPos(1,1)
	print ()
	print ("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
	print ("--------------------------------------------------")
	print ()
	print (" Welcome to the Nuclear Reactor Mainframe!")
	print ()
	print ("Please Choose an Action")
	print ("1. Reactor Menu")
	print ("2. Early Warning Systems")
	print ("3. Emergency Shutdown")
	print ("4. Cooldown Settings")
	e, p = os.pullEvent()
	--make sure we are handling a char event before checking the parameter.
	if e == "char" then
		if p == "1" then
			reactorMenu()
		elseif p == "2" then
			print ("hi")
		end
	end
end

Ok, wow, I cannot thank you enough, man. This thing is lookin' pretty sweet, all thanks to you. I now have it working properly, and the rest won't be hard.

I am truly grateful! Thank you SOOOOO much, man!

@HelenB: I plan on finishing the scripting tomorrow, haven't tested the programming to it's full extent but have tested failsafes, and they seem to be working. I'll work hard to get the finished product out tomorrow!

THANK YOU SOOOO MUCH
to everyone who helped!
AWESOME! :)/>/>
Can't wait to see it! :3
I can now abandon my old computer powered power plant because it has a bad design. That's if this script works ofc. lol
Reactor 4 just exploded anyway :o/>/>