Counters are G.js’s primary abstraction over GD’s item system. They wrap a numeric item ID and expose a chainable API for arithmetic, conditional branching, and display.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/g-js-api/G.js/llms.txt
Use this file to discover all available pages before exploring further.
float_counter extends the integer counter with floating-point support, and timer creates a time-based counter driven by the level clock.
For a higher-level guide see Counters and Conditions.
counter
Creates a new counter backed by a GD item ID. By default a fresh item ID is allocated automatically.Initial value. Can be a number or boolean.
When
true, treats num as an existing item ID rather than an initial value.Keeps the counter value across attempts.
Creates the counter as a timer item.
Number of bits to use for the counter. Affects maximum storable value.
Counter.
float_counter
Version ofcounter that supports floating-point values. Adds round(), floor(), and ceil() methods on top of the standard Counter interface.
Initial floating-point value.
When
true, treats val as an existing item ID.Keeps the value across attempts.
FloatCounter.
timer
Creates a time-based counter that counts up (or down) in real seconds using GD’s timer system. The returnedCounter also exposes start(), stop(), set_start(), and set_end() methods.
Initial time value in seconds.
Time value at which the timer fires the target group.
Group to call when the timer reaches
end_seconds.Count downward instead of upward.
Only count full seconds (no sub-second precision).
Stop the timer automatically when it reaches
end_seconds.Multiply the timer’s speed by this value. Cannot be used when
backwards is true.Ignore the level’s timewarp trigger when ticking.
Prevent another timer from overriding this one.
Counter.
Counter Interface
Every counter returned bycounter(), float_counter(), or timer() implements the following interface.
Properties
The underlying GD item ID. Pass this to
item_edit, item_comp, or count when you need raw item access.Item type constant.
1 = ITEM, 2 = TIMER.Bit width of the counter, or
undefined if unset.Arithmetic Methods
Each arithmetic method returns the counter itself to allow chaining. Theamount argument can be a plain number or another Counter.
Adds
amount to the counter.Subtracts
amount from the counter.Multiplies the counter by
amount.Divides the counter by
amount.Sets the counter to
amount.Sets the counter to
counter % b.Takes the absolute value of the counter.
Negates the counter.
Resets the counter to zero.
Copy / Transfer Methods
Adds this counter’s value to another counter.
Copies this counter’s value to another counter.
Subtracts this counter’s value from counter
b.Creates a new counter with the same current value.
Conditional & Conversion Methods
Calls
trig_func when the condition counter [comparison] other is true. Use the EQUAL_TO, LARGER_THAN, or SMALLER_THAN constants for comparison.Iterates over
range and calls cb(val) for each value that matches the counter. Useful for runtime branching on counter values.Converts the counter to a raw
GJsObject for use in object dictionaries.Places an item-display trigger at position
(x, y) that shows this counter’s value on screen.Code Example
FloatCounter Additional Methods
FloatCounter extends Counter with three rounding helpers, each of which returns the FloatCounter for chaining.
Rounds the value to the nearest integer.
Floors the value to the nearest integer below.
Ceils the value to the nearest integer above. (Exposed via the core
FloatCounter interface.)ceil() is defined in the FloatCounter TypeScript interface (core.d.ts) but the declaration file lists it alongside floor() as a method returning FloatCounter. Treat it as equivalent to floor() for upward rounding.