PaleFox
Well-known member
This whole discussion is what I mean that the devs don't understand the difference between ++i and i++
- Current (buggy): like i++ → keeps giving the “old” state first, pushes the update later, which breaks the heartbeat tick.
- Correct (intended): like ++i → increments state first, then immediately uses it, so ticks happen on time.
// onHit event: buggy version
onHit(target):
effect = target.getEffect("GlassShards")
if effect != null:
effect.duration = 20
effect.timer = 0 // ❌ resets tick timer every hit
effect.stacks = effect.stacks++ // ❌ post-increment style: "use old value" → stacks effectively stay 1
else:
applyEffect(target, stacks=1, duration=20, timer=0)
// heartbeat (ticks damage)
heartbeat(delta):
for effect in allEffects:
effect.timer += delta
if effect.timer >= 2:
applyDamage(effect.owner, effect.stacks * roll(5d10))
effect.timer -= 2
// onHit event: intended version
onHit(target):
effect = target.getEffect("GlassShards")
if effect == null:
// first hit: create effect and start timer at 0
applyEffect(target, stacks=1, duration=20.0, timer=0.0)
else:
if effect.stacks < MAX_STACKS:
++effect.stacks // ✅ pre-increment: increment first, then use → stacks grow immediately
effect.duration = 20.0 // refresh duration
// ❌ DO NOT reset effect.timer → tick continues independently
// heartbeat (ticks damage)
heartbeat(delta):
for effect in allEffects:
effect.timer += delta
while effect.timer >= 2.0:
applyDamage(effect.owner, effect.stacks * roll(5d10))
effect.timer -= 2.0
effect.duration -= delta
if effect.duration <= 0:
removeEffect(effect)