Skip to content
Dashboard

In-Memory Aggregators

In fast-paced games, certain events occur dozens of times every minute: firing weapons, taking damage, collecting small items, or dodging obstacles. Emitting individual HTTP events for each action creates unnecessary network overhead and pollutes database tables.

The LogLudo SDK provides In-Memory Aggregators (aggregate_add and aggregate_pop) to accumulate client-side metrics in memory and dispatch the calculated statistical summary when a level, match, or wave ends.


Aggregators live inside the LOGLUDO._aggregates struct. When you call LOGLUDO.aggregate_add(), the SDK dynamically creates or updates an accumulator. When you call LOGLUDO.aggregate_pop(), it computes the final metric, deletes the accumulator from memory, and returns the formatted result.

The SDK supports three distinct aggregation types:

Type How It Accumulates What aggregate_pop() Returns Best Used For
"sum" Increments running total (value += _value) Real number (total sum) Total gold collected, bullets fired, jumps made
"average" Tracks running sum and total count Real number (sum / count) Average damage per hit, frame time, reaction delay
"frequency" Tallies frequency map of stringified keys Sorted array of top 10 items [{ item, count }] Favorite weapons, spells used, death hazards

Use "sum" to track cumulative quantities throughout gameplay without dispatching an event on each collection:

obj_apple Collision Event
// Increment the running sum of apples collected
LOGLUDO.aggregate_add("apples_eaten", 1, "sum");
instance_destroy();
obj_gold_chest Open Event
// You can add any positive or negative real number
LOGLUDO.aggregate_add("gold_earned", 150, "sum");

Use "average" to compute the mean value across multiple samples. The SDK tracks both the sum and the sample count, automatically dividing them upon pop:

obj_player Damage Script
function player_take_damage(_damage_amount) {
hp -= _damage_amount;
// Add damage value to the running average
LOGLUDO.aggregate_add("damage_per_hit", _damage_amount, "average");
}

When popped, if 5 hits were taken with values [10, 20, 15, 30, 25], LOGLUDO.aggregate_pop("damage_per_hit") returns 20. If zero hits occurred, it safely returns 0.


Use "frequency" to identify player preferences, common choices, or frequent hazards. Every time a value is added, its string representation is tallied in a frequency dictionary.

Weapon Firing Script
function player_fire_weapon(_weapon_name) {
// Tally weapon usage
LOGLUDO.aggregate_add("weapons_used", _weapon_name, "frequency");
}
// Example calls:
player_fire_weapon("shotgun");
player_fire_weapon("shotgun");
player_fire_weapon("plasma_rifle");
player_fire_weapon("rocket_launcher");

When you pop a "frequency" aggregator, the SDK:

  1. Iterates over all keys in the frequency map.
  2. Sorts items in descending order of popularity.
  3. Automatically truncates the array to the top 10 most frequent items.
  4. Returns an array of structs:
    [
    { "item": "shotgun", "count": 2 },
    { "item": "plasma_rifle", "count": 1 },
    { "item": "rocket_launcher", "count": 1 }
    ]

Here is how all three aggregators combine into a single, clean progression event when the player completes a level:

obj_goal_door Collision Event
/// @desc Player reached the exit door
// Pop all accumulated metrics into local variables (clearing them from memory)
var _total_apples = LOGLUDO.aggregate_pop("apples_eaten");
var _avg_damage = LOGLUDO.aggregate_pop("damage_per_hit");
var _weapon_stats = LOGLUDO.aggregate_pop("weapons_used");
// Dispatch a single consolidated progression event
LOGLUDO.send_action("progression", "level_complete", {
level_id: room_get_name(room),
clear_time_seconds: round(level_timer),
metrics: {
apples_collected: _total_apples,
average_damage_taken: _avg_damage,
top_weapons_used: _weapon_stats
},
scenelytics: {
type: "point",
pointType: "dot",
x: x,
y: y,
color: "#10b981"
}
});
// Transition to next level
room_goto_next();