tick
Run your scripts in the background
Running in a tick
registerTick(function ()
{
client.print(`hello from script! | tick at: ${env.TickCount}`);
});Tick rate
setTickRate(1);
registerTick(() =>
{
client.print(`Hello every 1ms! | tick at: ${env.TickCount}`);
});In this script, you can control how often a task runs by setting a "tick rate." The tick rate determines how fast the system performs actions, and is measured in milliseconds.
setTickRate(ms): Sets how often the task runs. For example,setTickRate(1)will make the task run every 1 millisecond, whilesetTickRate(16)makes it run about 60 times per second.registerTick(callback): Registers a function (callback) that will be executed every time the tick happens. You can use this to run specific code repeatedly based on the tick rate.
This gives users the flexibility to adjust the speed of recurring tasks (ticks) and register actions that will be triggered at the set interval. By default the tick rate is 16.
High precision ticking
When and Why to Use It
This option allows you to choose between two ticking behaviors inside of the JavaScript Engine β one optimized for general use, and one designed for more sensitive, real-time tasks.
π Comparison: Normal vs. High-Precision Mode
Tick Timing
Relaxed pacing between loop iterations
Tightly controlled loop execution
Timing Accuracy
Good for general scripting
More consistent for time-sensitive logic
Responsiveness
Suitable for most background operations
Ideal for real-time or input-driven behavior
CPU Usage
Low
Higher (due to faster, tighter loop activity)
Best For
Automation, monitoring, passive logic
Rapid polling, low-latency tasks, Human like timing
Scalability
Efficient across many scripts
Best used selectively
β
When to Use Each Mode
Normal Mode
Great for:
Periodic logic and automation
Scripts that donβt require microsecond accuracy
Lower CPU impact for background behavior
High-Precision Mode
Best for:
Polling memory or tracking state changes rapidly
Scripting that requires stable frame pacing or tick intervals
π§ Summary
The engineβs tick system runs continuously in a loop.
In normal mode, the loop runs at a steady, relaxed pace β ideal for most script scenarios with minimal CPU usage.
In high-precision mode, the loop is optimized to execute ticks more tightly and consistently, offering improved timing behavior at the cost of increased system usage.
You can toggle the mode dynamically like this:
highPrecisionTicking(true);
highPrecisionTicking(false);Example:
highPrecisionTicking(true);
setTickRate(1);
registerTick(() =>
{
});FPS not as expected?
π― 60β70 FPS is normal
Our JavaScript engine's tick system is designed to run at approximately 60 frames per second (FPS) by default β a common and efficient target in real-time systems. This interval (typically ~16 milliseconds per tick) balances responsiveness and performance, ensuring scripts run smoothly without consuming excessive CPU resources.
Due to natural variations in system scheduling, background load, and OS timing resolution, the actual measured FPS may fluctuate slightly β usually landing between 60 and 70 FPS. This is expected and acceptable for most use cases, especially when extremely high timing precision is not necessary.
π§ What About highPrecisionTicking(true)?
highPrecisionTicking(true)?Enabling high precision ticking modifies the tick system to use a more aggressive scheduling loop for tighter timing. This can improve input responsiveness and memory polling accuracy when very low latency is important.
However, itβs important to note:
β οΈ High precision ticking does not increase FPS.
Even with the most precise loop, youβre still constrained by:
How fast your CPU can run the loop while sharing resources with other threads.
OS-level limits on thread scheduling granularity.
Overhead from the tick function logic itself (especially if interacting with devices or processes).
In practice, you may still observe around 60β70 FPS, even in high precision mode β just with lower jitter and more consistent timing, which can be beneficial for tasks like:
Precise input simulation
Smoother memory polling
Minimizing frame skip
π Comparison: CPU Usage vs. Precision
Precision Mode
βββββββββββββββββββββ 12β15% CPU
β³ Lower latency, tighter control
Standard Mode
ββββββ 0.5β2% CPU
β³ Efficient for most tasksLogging tick FPS
var lastTick = env.TickCount;
var fps = 0;
highPrecisionTicking(true);
setTickRate(1);
registerTick(() =>
{
var now = env.TickCount;
var delta = now - lastTick;
if (delta > 0)
{
fps = Math.round(1000 / delta);
lastTick = now;
}
client.print(`Tick at: ${now} | Estimated FPS: ${fps}`);
});Last updated
Was this helpful?