How to create an expiration code for a Lua menu?

Runbu73

Участник
Автор темы
118
3
How can I make a menu expire/stop working after a certain period? Can someone please help me? I've been trying to do this for a long time and can't figure it out/find it.
 

qqvx

Участник
29
13
How can I make a menu expire/stop working after a certain period? Can someone please help me? I've been trying to do this for a long time and can't figure it out/find it.
here’s an example of how to implement a menu expiration system in Lua:

Lua:
local menuActive = true
local menuDuration = 60
local startTime = os.time()

function checkMenuExpiry()
    local currentTime = os.time()
    if currentTime - startTime >= menuDuration then
        menuActive = false
        print("Menu has expired.")
        
    end
end

while true do
    checkMenuExpiry()
    
    if menuActive then
        print("Menu is active.")
    else
        break
    end
    
    os.execute("sleep 1") -- Sleep for 1 second (on Linux/Mac)
    -- For Windows, use: os.execute("timeout /t 1 > nul")
end

Explanation of the Code:
  1. menuActive: A flag indicating whether the menu is active.
  2. menuDuration: The duration for which the menu will remain active, in seconds.
  3. startTime: The time when the menu started.
  4. checkMenuExpiry: A function that checks if the menu has expired.
  5. Loop: The main loop that calls the check function and runs the menu code while it's active.
you can adapt this code to fit your specific implementation and context.
 
  • Нравится
Реакции: Naito и sizeoftrickster