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

Making a Pretty Menu

Started by Eagle4Life69, 13 August 2012 - 09:07 PM
Eagle4Life69 #1
Posted 13 August 2012 - 11:07 PM
I would love help on creating a pretty menu system for my shopping mall, like an information kiosk.

I am new to Lua and Computer Craft only creating basic programs with basic 2 deep menus. Here is my issue I have a menu and it loads first set fine, then press option 1 it goes into it, but then any button sends it to main menu.

Please help here is my code I have now let me know how to do it better and correctly.

Thanks

bOut = 0
function Main_Menu()
while true do
  term.clear()
  term.setCursorPos(1,1)
  --clearscreen()
  print ( [[
   +********************************+
   |								|
   |	   Information  Kiosk	   |
   |								|
   +--------------------------------+
   |		 Please Choose		  |
   |  1. Store Directory			|
   |  2. How to Buy				 |
   |  3. How to Sell				|
   +********************************+
  ]] )
  os.pullEvent = os.pullEventRaw
  e, p = os.pullEvent()
  if e == "char" then
   if p == "1" then
	Store_Directory()
   elseif p == "2" then
  
   elseif p == "3" then
  
   else
  
   end
  end
end
end
function Store_Directory()
term.clear()
term.setCursorPos(1,1)
print ( [[
  +********************************+
  |								|
  |		Store  Directory		|
  |								|
  +--------------------------------+
  |  A. Fire Items				 |
  |  B.							|
  |  C.							|
  | press 0 to return to main menu |
  +********************************+
]] )
os.pullEvent = os.pullEventRaw
e, p = os.pullEvent()
  if e == "char" then
   if p == "a" then
	term.clear()
	term.setCursorPos(1,1)
	print ( [[
	 +********************************+
	 |								|
	 |		 Fire  Items		  |
	 |								|
	 +--------------------------------+
	 |	You can find Fire Items	 |
	 |		   in store #		   |
	 |			   21			   |
	 |	 Upper level  left side	 |
	 +********************************+
	]] )
	sleep(5)
	Main_Menu()
   elseif p == "b" then
	
   elseif p == "c" then
	
   elseif p == "0" then
	Main_Menu()
   else
	
   end
  end
end
Main_Menu()
cant_delete_account #2
Posted 13 August 2012 - 11:13 PM
Check this out:
A quick guide through menu making
Noodle #3
Posted 14 August 2012 - 03:18 AM
You don't need an else
You don't want a "os.pullEvent = os.pullEventRaw" everywhere with the loops
I think the reason you go back is that it ends the loop (due to else) then goes to bottom of code where it resumes Main_Menu()
Eagle4Life69 #4
Posted 14 August 2012 - 03:23 AM
ok… Is there a way to tell if someone has walked away from the computer and have it reset the menu to the beginning?
Noodle #5
Posted 14 August 2012 - 03:25 AM
No real way to do that
You could make a timer.. If they choose the menu they have a timeout to choose, if they don't choose in time then it'll reset.
Eagle4Life69 #6
Posted 14 August 2012 - 03:32 AM
ok how to add timer?
would I use os.startTimer
Noodle #7
Posted 14 August 2012 - 03:35 AM
Yes then it throws an event when it timesout.
http://computercraft.info/wiki/index.php?title=Os.pullEvent
Scroll to bottom for list of events.
Eagle4Life69 #8
Posted 14 August 2012 - 03:42 AM
Perfect thanks so much
KaoS #9
Posted 15 August 2012 - 02:26 PM
detect them pressing the escape button to leave