Skip to content

Godot plugin for executing a code snippet, with a fixed time delay between each call.

Notifications You must be signed in to change notification settings

foopis23/Godot-Interval-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Godot Interval System

Godot Plugin for executing a code snippet, with a fixed time delay between each call. This an alterative to Godot's Timer node.

Usage

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)

Installation

  1. Download the repository
  2. Copy the addons folder to your project folder
  3. Enable the plugin in the project settings

Notes

Timing Accuracy

Intervals can only be processed once per frame process. Low frame rates can produce inaccurate interval times.

Reference

IntervalSystem

Properties

Type Name
Dictionary intervals

Methods

Returns Method
int create(intervalInSeconds: float, callable: Callable, deferred = false, src: Node = null)
bool clear(intervalId: int)

Property Descriptions

Dictionary intervals = {}

The dictionary containing all the intervals

Method Descriptions

int create(intervalInSeconds: float, callable: Callable, deferred = false, src: Node = null) -> int

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.

clear(intervalId: int) -> bool

Clears the interval with the given id. Returns true if the interval was cleared, false if it was not found.

Interval

Properties

Type Name
int id
float intervalInSeconds
Callable callable
bool deferred
Node src
float elapsed

Methods

Returns Method
void _init(_id: int, _intervalInSeconds: float, _callable: Callable, _deferred = false, _src: Node = null)
void run()

Property Descriptions

int id

The id of the interval

float intervalInSeconds

The time between each call

Callable callable

The function to call each time

bool deferred

If the function should be called in idle time

Node src

The node that the interval is attached to (if any). This is used to automatically clean up the interval when the node is deleted

float elapsed

The time elapsed since the last call

Method Descriptions

void _init(_id: int, _intervalInSeconds: float, _callable: Callable, _deferred = false, _src: Node = null)

Constructor for the interval

void run()

Runs the callable and handles deferred vs immediate execution

About

Godot plugin for executing a code snippet, with a fixed time delay between each call.

Topics

Resources

Stars

Watchers

Forks