Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Ability Cooldown System
Track ability cooldown durations and check ready status against elapsed timestamps.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Game Systems). Copy the parameterized template or run the self-contained example.
- 1Category: Game Systems
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
a AbilityCooldown has
abilityName
cooldownSeconds
lastUsedAt
.
to createAbility name cd
ability is a AbilityCooldown
abilityName of ability is name
cooldownSeconds of ability is cd
lastUsedAt of ability is 0 minus 9999
return ability
.
to isAbilityReady ability nowSeconds
last is lastUsedAt of ability
duration is cooldownSeconds of ability
elapsed is nowSeconds minus last
if elapsed is at least duration
return true
otherwise
return false
.
.
to useAbility ability nowSeconds
ready is isAbilityReady ability nowSeconds
if ready is true
lastUsedAt of ability is nowSeconds
return true
otherwise
return false
.
.
a AbilityCooldown has
abilityName
cooldownSeconds
lastUsedAt
.
to createAbility name cd
ability is a AbilityCooldown
abilityName of ability is name
cooldownSeconds of ability is cd
lastUsedAt of ability is 0 minus 9999
return ability
.
to isAbilityReady ability nowSeconds
last is lastUsedAt of ability
duration is cooldownSeconds of ability
elapsed is nowSeconds minus last
if elapsed is at least duration
return true
otherwise
return false
.
.
to useAbility ability nowSeconds
ready is isAbilityReady ability nowSeconds
if ready is true
lastUsedAt of ability is nowSeconds
return true
otherwise
return false
.
.
spinAttack is createAbility "Whirlwind" 4
readyInitial is isAbilityReady spinAttack 0
if readyInitial is not true
fail with "ability expected ready initially"
.
usedOk is useAbility spinAttack 0
if usedOk is not true
fail with "ability use expected to succeed at t=0"
.
readyAt2 is isAbilityReady spinAttack 2
if readyAt2 is not false
fail with "ability expected on cooldown at t=2"
.
readyAt5 is isAbilityReady spinAttack 5
if readyAt5 is not true
fail with "ability expected ready at t=5 after 4s cooldown"
.
say "Cooldown checks passed successfully."
Installation & Usage
otter snippet inspect game-cooldown-system
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.