add feautures to BGE (EASY) -> bge.tick and bge.callBacks


i found often the necessity of some tick as reference .

it cam be done internally to the object itself (each frame >> tick += 1)
but is not necessarly(can just by chance) “synced” with other object.
plus , is better one tick rather than 200 (performances)
i discovered this lack often, lastly is to make message : how know if a message is old?(it can be 1 hour old or very new)
the messages(since is a list or dict that can become giant) should be cleaned each frame the messages old.

so the message can work in this way:

def sendMessage(self,ms,obTo):
    messages = obTo.messages
    tick = bge.tick
    if not tick in messages: 
        messages[tick] = []
    messages[tick].append((ms, self)) #or Message(ms,self)
    for k in [k for k in messages if k!=tick]:

(just a idea, maybe can be done from the object reader, or some other ways, but is doable if you have a “tick solid”)

the bge.tick cannot run on some dummy with “always true”, it must be done out of SCA (or before or after) out of range for a game object , otherwise is not “solid” (can be a wrong reference)

[curiosity : a int that each frame increase can become 36288000 … after ONE WEEK !!! i guess not should be a problem if is “infinite” , right?]

this should be as default(that not require custom code… i guess to a class read-only), strange that not there already… (or there somewhere?)

then, what about add some list of calls (not know if callbacks is the correct name) excactly as scene.pre_draw.
with the difference thar run OVER the scene , so, it is ever a reference in each scene,ex:

what you tink?

As far as the ‘tick’ feature goes, you can implement this in Python fairly simply. Just register a callback for the scene post-draw and log the current time in a global object. Then if everything checks the global object time, they will all see the same value. Checkout Monster’s game-loop diagram. Since the last thing that happens is scene rendering, then you will end up getting a new time right before your controllers are executed.

As for the callbacks that run ‘over the scene’, the Controllers are the callbacks that are executed once a frame. If you need something that does manager or game-level logic then most people add an Empty to the scene and use that Empty’s Controller for the game-level logic.

is what i do , using a “empty manager” that add a function on pre_draw . (i know the diagram gameloop of Monster, very well done)

anyway can happen some problem if there more than one scene since each scene need to a empty manager, but not in all scenes , for example not in the GUI(or only in the GUI) otherwise you have double update…
i really anyway not use much scene exaclty for these lack of control … a dummy manager do already a task that not should be done

a list of function(not scene dependent) where you can append something seem a solution much more clean …