Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to get the time of day
- function getTimeOfDay()
- local time = os.time() % 24000 -- Minecraft's time cycle is 24000 ticks
- if time < 5000 then
- return "Day"
- elseif time < 10000 then
- return "Evening"
- elseif time < 13000 then
- return "Sunset"
- else
- return "Night"
- end
- end
- -- Function to display the menu
- function displayMenu()
- print("===== In-game Timer Menu =====")
- print("1. View Current Time")
- print("2. Exit to GUI")
- print("Choose an option (1-2):")
- end
- -- Function to handle menu input
- function handleMenuChoice(choice)
- if choice == "1" then
- -- Display the current time and time of day
- local timeOfDay = getTimeOfDay()
- local currentTime = os.time() % 24000
- print("Time: " .. currentTime .. " (" .. timeOfDay .. ")")
- elseif choice == "2" then
- -- Exit to GUI using shell.run
- print("Exiting to GUI...")
- shell.run("/disk/os/gui") -- Use shell.run to execute the command
- return true
- else
- print("Invalid choice. Please try again.")
- end
- return false
- end
- -- Main loop
- while true do
- displayMenu()
- local choice = read() -- Wait for user input
- local exit = handleMenuChoice(choice)
- if exit then
- break -- Exit the loop if the user chooses option 2
- end
- sleep(1) -- Update every second
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement