Skip to content

Class

SpendByIdRule

Generated GDScript class reference for GridPlacement.SpendByIdRule.

Status
Current
Version
v6.2.1
Source updated
2026-09-24
Generated on
2026-10-22

Canonical id-keyed spend rule for direct provider injection. Extends SpendCostRuleBase to create the single concrete rule games use for id-keyed costs. Unlike SpendMaterialsRuleById, the provider is injected directly at construction time — no NodeLocator needed. Provider contract (duck-typed, enforced at runtime):
get_count_by_id(id: StringName) -> int
try_remove_by_id(id: StringName, amount: int) -> int
try_add_by_id(id: StringName, amount: int) -> int

The rule has no opinion about what the ids represent (currency, items, etc.) — the game expresses that by choosing which provider to inject. Usage: var provider := MyGameProvider.new() var rule := SpendByIdRule.new({&"Gold": 100}, provider)

Source: addons/grid_placement/placement/placement_rules/template_rules/spend_by_id_rule.gd

Syntax

class SpendByIdRule extends SpendCostRuleBase