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

How to re-start a loop after it has been exited?

Started by Ken, 31 May 2015 - 10:33 AM
Ken #1
Posted 31 May 2015 - 12:33 PM
Hi, i have taken a tutorial from a YouTuber to make a clickable menu. I am aware of how to make the buttons run functions, which wasn't provided in the tutorial, but I would like to make a button, at the bottom of the screen after a button has been pressed, that takes me back to the main menu (restarting the loop).
Here is the code:


pastebin.com/SXsC4uRa

for example, after the first button , as well as it printing "Doors Locked!", it also has a button at the bottom of the screen to exit out of that button, back to the menu?
Any help would be appreciated, sorry if this has been answered before, I had no idea what to search to find it! :/
HPWebcamAble #2
Posted 31 May 2015 - 05:23 PM
The way I make menus is like this:



--# Initialize variables

local function drawSubMenu()
    while true do
        --# display menu
        while true do --# Wait for input for THIS menu
            local event = {os.pullEvent()}
        end
    end
end


while true do

--# display main menu

  while true do
    local event = {os.pullEvent()} --# Wait for input

    if event[1] == "mouse_click" then --# For example...

      drawSubMenu()

    end

  end

end


so basically it draws the first menu, then when it gets the input it was looking for (say a key getting pressed or a part of the screen getting clicked),
it draws subsequent menus. When those menus' loops finish (Becuase they have done what they needed to do),
the main menu loop continues from where it left off