ludic/examples/library/input_auto.ludic
Orkuncakilkaya 19fcf60599 wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run
ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:31:34 +03:00

22 lines
1,009 B
Text

# input_auto.ludic — proves the frame loop commits the device layer automatically
# (#83): a real handler game reads Input.active in its Update phase and NEVER calls
# Input.poll by hand, yet the action fires from the live key. Before this fix the
# loop only fed Input.key(), so Input.active read empty unless the game polled.
#
# Driven headless by the keys on stdin — one char per frame. With "llq": frame 1
# and 2 read 'l' (the action key), frame 3 reads 'q' (which quits). So the action
# is active on exactly two frames.
#
# Run: printf 'llq' | bin/ludic examples/library/input_auto.ludic -> 2
program InputAuto {
property Tag { n: int = 0 }
model Player { Tag }
state InputAutoState {
hits: int = 0
}
@OnStart handler Boot { Input.action("go", 'l') } # 'l' == 108
handler Sense(input_auto_st: mut InputAutoState) phase Update { if Input.active("go") { input_auto_st.hits += 1 } }
@OnQuit handler Report(input_auto_st: InputAutoState) { print(input_auto_st.hits) }
}