How to use os.clock to get time until in game events

Hello! I own a group game that hosts something called awards daily. These awards are at various times. I would like to make a script that checks which of these times is closest and then checks the amount of time from now until then. Note that more of these times are added each day so I can’t just add a static time to the script. I’m not sure how to implement this even after reviewing the documentation so any advice would be appreciated.

1 Like

You’ll more likely want to use os.time to do all of those calculations.

To find the nearest time, you can either write your own function or use table.sort to find the earliest time:

table.sort(events,function(a,b)
	return a.Time < b.Time
end)
-- events[1] would be the earliest event.

Each event table would probably have event.Time (their timestamp) and event.Event (any other event information or instance reference).

1 Like