   Scripts and Time
  I''ve been thinking about this for awhile now. The concept I''m trying to grasp is how to time and scripts work together correctly with an engine while its running. Here are the ways that I have thought about:1. The engine controls the time that the script is fired. But what about scripts that have to do with time? (i.e. like a timer that counts down to 0).2. The script controls when it fires next by making calls to the engine timer. Problem with this is I don''t know when, or how, the script would know that it needs to call a function to get the time.3. The scripts are run through every loop whether they need updating or not. IMO This seems like the lazy way to do it.So am I missing something? Also notice I left this post scripting language independent. If its at all possible I''d like it to be that way, although I don''t mind concise examples from languages. 
  hum...For what I know, there are two commonly used system :* ) A script scheduler : every script is told to be launch at a specific time. It can be every time, every seconds, ...My ( and a lot of other''s ) solution is based on the assumption that you have to put as much that you can on the script side, so the script is called every time, has access to a getTime engine function, and decide to do something or to return...Hope it helps,  ;  Here's some relevant links:* http://gamedev.net/community/forums/topic.asp?topic_id=170184* An article on python "weightless threads" or "microthreads": http://www-106.ibm.com/developerworks/linux/library/l-pythrd.htmlHere's a description of my scripting interface that I wrote in response to someone else's problem a while back on this forum.  I use your second method, where the script is resposible for letting the script scheduler know when to next schedule it.  Pasted here:In my engine, I use only the Very High Level Embedding to call python. I wrap PyRun_SimpleString myself to provide error checking, but that is unnecessary here.PyRun_SimpleString("import sys");PyRun_SimpleString("sys.path.append("./scripts");PyRun_SimpleString("import scheduler");PyRun_SimpleString("secheduler.load('ascript')");while (true)   PyRun_SimpleString("scheduler.update()"); In other words, I have a class written in Python that calls out to other scripts.Then, in the scripts, I doimport enginedef main()   ...   yield 1 #return the number of seconds to wait  #before updating this script again.   #Next time the script is given execution  #time, it will resume at the yield statement  #(read the python docs on 'generators')    where engine is a static python extension module (exposed using boost.python).(code here)http://urbanhunting.com/~dustin/katana2/script.cpphttp://urbanhunting.com/~dustin/katana2/internal.pyhttp://urbanhunting.com/~dustin/katana2/example.py edit: minor corrections to better explain things--Dustin [edited by - thedustbustr on February 7, 2004 9:18:08 PM] [edited by - thedustbustr on February 7, 2004 9:22:48 PM];  You can probably use a priority queue to store the times at which events are to take place. Each time through the game loop you generally only have to check the first event in that queue to see if it''s ready, making this an efficient approach.   [ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost  Asking Questions | Organising code files | My stuff | Tiny XML | STLPort] 