0 of 0

File information

Last updated

Original upload

Created by

Rendara

Uploaded by

Rendara

Virus scan

Safe to use

Tags for this mod

About this mod

This is an efficient Python timer that can fire off functions at set intervals. No need to restrict yourself to maps with logic_timer entities - this implementation works in any map, out of the box.
An example map and accompanying script is available for download.

Requirements
Permissions and credits
Explanation

While I was scripting a diablerie function for someone on PV, I was frustrated that timer functionality was locked behind the logic_timer entity, which isn't embedded into many maps. For a new global function, this would require recompiling every map that didn't have the entity, which I wasn't prepared to do. So I wrote this as a completely independent scripted timer instead.

I don't think I'm the first person to do this because it's such a simple block of code, however I've not seen any documentation for this specific solution in any major modification. There is a "time"  module that can be imported into any level script but I found it to be highly inefficient and overkill for a timer, so you should experiment with that too and consider your own use case accordingly.


Instructions


To test, open the console on the title screen and submit "map re_timer". Once you load into the map, open the console again and submit "unpause". You'll see an update message being printed to the console every second, for twenty seconds. This may look like a logic_timer output, but it isn't. You can decompile the map and see for yourself, it has no entity except for info_player_start.

Once you have a grasp of what's happening in-game, navigate to the timer.py script and tweak the loop range parameter and seconds variable. These change how many threads will be fired in total, and how long the intervals between firing are, respectively.

Please note that any threaded function parameters will always be taken from the end of the currently executed block/loop BEFORE their
time of execution.
For example, if the timer.py loop was specifying "myFunc(seconds)", then the passed parameter value would be "20" for ALL
of the threaded functions, even if the thread was scheduled while the value was different.
Thankfully this limitation has an easy workaround - global variables. See the "number" variable in the timer.py script as a simple example of how global vars can be applied in lieu of threaded parameter passing.

If you plan on using this and expanding it for your own project, I strongly recommend that you insert this functionality into your vamputil.py script so that it can be called from anywhere.