English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can someone suggest to me how to execute a function every X seconds? I need this for a game where I need to spawn a unit every, say, 5 seconds.

There's a function in the programming language that I'm using (python), that keeps track of time from the moment the game starts.

Thanks!

2007-05-04 19:07:19 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

Just put a counter in your main loop if you have one. Check the value of that function modulo 5 and see if it is > than your counter, if so then run the function.


If your application is multithreaded you can spawn a new thread containing:
{
while true
sleep 5
spawn unit
end while
}

Obviously this isn't python code, but it should give you an idea of how you can do what you want.


You may also find the resettable timer class useful
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464959

2007-05-04 19:29:09 · answer #1 · answered by Vegan 7 · 0 0

fedest.com, questions and answers