G
G
Gleb868989642021-02-10 17:05:35
Lua
Gleb86898964, 2021-02-10 17:05:35

Working with time in Lua?

How can you perform an action in Lua on time? For example, the first line of code is executed, then we wait 3 seconds and execute further according to the algorithm.
How to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-02-10
@vabka

sleep

D
dollar, 2021-02-11
@dollar

Depends on what time management tools are provided by the runtime (that is, the parent application where Lua is embedded).
For example, if the parent application constantly calls the global Update() function, and the os.time() function is also available, then you can detect the time at the very beginning, and then periodically read it again inside Update(). Each time we compare the new time with the initial one. As soon as the difference is more than 3 seconds, then it's time to move on. Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question