M
M
Mage From The Space2016-11-05 11:47:03
Game development
Mage From The Space, 2016-11-05 11:47:03

How to implement "Delay" function in love2d (lua)?

Please help with "Delay" function in lua language with love2d plugin. I searched on Google and found a feature that VERY slows down the game.
For example, I will write an excerpt from my code. :D Sorry for the "Russian-English" comments.
subspeed = 5 --Wichitanie goloda za odnu minutu--
function hungersubstract(subspeed)
playerhunger = playerhunger - subspeed
--tut nuzhen delay na odnu minutu--
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-11-05
@Magefts

You don't need a delay function - otherwise you will freeze the main thread.
Usually this is done like this - the time is remembered when the next change needs to be made, each frame it is checked whether this time has come (currentTime >= targetTime - necessarily an inequality), and if it has come, the necessary actions are taken and a new time is calculated.
You can wrap all this in a timer class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question