| name | fxgl-variables-events |
| description | Manage reactive game state in FXGL — declare typed world variables in initGameVars, read/write/increment them via DSL, bind JavaFX UI properties to live variable values, register property-change listeners triggered at specific thresholds, fire and subscribe to custom events on the EventBus, use the built-in game timer (runOnce, runAtInterval), and create offline timers that persist between sessions. Use this skill when tracking score, lives, time, game flags, wiring HUD to game state, implementing event-driven logic, or scheduling delayed/recurring actions.
|
| triggers | ["game variable","initGameVars","EventBus","property binding","reactive","inc","geti","getip","onIntChangeTo","game timer","runOnce","runAtInterval","world properties","fire event"] |
| compatibility | Java 17+, FXGL 21.x
|
| category | fxgl/state |
| tags | ["fxgl","java","javafx","state","variables","events"] |
| metadata | {"author":"fxgl-skills","version":"1.0","fxgl-version":"21.1"} |
| allowed-tools | ["Read","Write","Edit","Bash"] |
FXGL Variables & Events
Declaring Variables
All variables must be declared in initGameVars. FXGL creates strongly-typed
Property objects for each entry — use them for reactive UI bindings.
@Override
protected void initGameVars(Map<String, Object> vars) {
vars.put("score", 0);
vars.put("lives", 3);
vars.put("health", 100.0);
vars.put("hasShield", false);
vars.put("playerName", "Hero");
vars.put("currentLevel", 1);
vars.put("inventory", new ArrayList<Item>());
}
Reading & Writing at Runtime
int score = geti("score");
double hp = getd("health");
boolean shield = getb("hasShield");
String name = gets("playerName");
List<Item> inv = geto();
set(, );
set(, );
set(, );
inc(, +);
inc(, -);
inc(, +);