Godot Plugin for executing a code snippet, with a fixed time delay between each call. This an alterative to Godot's Timer node.
Creating an interval is simple. Just call the create
method with the interval time in seconds, the function to call, and optionally if the function should be called in idle time and the node that the interval is attached to (if any. Passing a node will clear the interval when the node is removed from the scene tree). The method will return an id that can be used to clear the interval.
IntervalSystem.create(2, func(): print("hello world"), false, self)
- Download the repository
- Copy the
addons
folder to your project folder - Enable the plugin in the project settings
Intervals can only be processed once per frame process. Low frame rates can produce inaccurate interval times.
Type | Name |
---|---|
Dictionary | intervals |
Returns | Method |
---|---|
int | create(intervalInSeconds: float, callable: Callable, deferred = false, src: Node = null) |
bool | clear(intervalId: int) |
The dictionary containing all the intervals
Creates a new interval that will call "callable" every "intervalInSeconds" seconds. If "deferred" is true, the function will be called in idle time. If "src" is not null, the interval will automatically clean itself up when the node is deleted. Returns the interval id for manual cleanup.
Clears the interval with the given id. Returns true if the interval was cleared, false if it was not found.
Type | Name |
---|---|
int | id |
float | intervalInSeconds |
Callable | callable |
bool | deferred |
Node | src |
float | elapsed |
Returns | Method |
---|---|
void | _init(_id: int, _intervalInSeconds: float, _callable: Callable, _deferred = false, _src: Node = null) |
void | run() |
The id of the interval
The time between each call
The function to call each time
If the function should be called in idle time
The node that the interval is attached to (if any). This is used to automatically clean up the interval when the node is deleted
The time elapsed since the last call
void _init(_id: int, _intervalInSeconds: float, _callable: Callable, _deferred = false, _src: Node = null)
Constructor for the interval
Runs the callable and handles deferred vs immediate execution