GameApp.Run takes the engine's options (--headless, --frames, --connect ...) and, in development builds, the development options (--live, --scenario, --capture ...). A game adds its own by declaring their names:
public sealed class MyGame : GameDefinition { public override IReadOnlyList<string> OptionNames => ["level", "fake-store"]; // ... }
- Works in every build. A declared option never needs the development tools:
mygame --level 3runs the same in a release export, and beside--liveor--scenarioin a development build. - Read it from the instance.
GameInstance.Argsis aGameArgs:Has("fake-store"),Get("level"),GetInt("level", 1). Use it in view and host code (screen builders,OnEachFrame, the code that creates services). Sim code must not: the command line is not part of the world, the recording or the snapshot, so reading it would make a replay depend on how the game was started. Sim code has no way to reach it (a world does not hold the instance), and a static that carries it into an entity is outside API the sim analyzers warn about (OG0015, an error under warnings-as-errors). - Misspelt options still fail. Only the declared names are exempt.
--scenaroin a release build exits 5no_dev_tools, and in a development build exits 2bad_args("Unknown option --scenaro"); both messages list the game's own options. A declared name that is also an engine or development option is that option's, not the game's. Names are given without dashes, spaces or=; anything else exits 2bad_game_option. - Syntax.
--name value,--name=valueor a bare--name(a flag). A bare flag directly before a non-dash word takes that word as its value, so put flags last or write--flag=true. - Where the line comes from. Desktop and
onegame run -- --level 3pass the arguments straight through (everything after--is the game's). Android: the launch intent'sonegame.argsextra (-e onegame.args "'--level 3'";onegame android run|test|liveforward their game arguments the same way). iOS: the process launch arguments (simctl launch <device> <bundle> --level 3). Browser: whatever arguments the page's host passes toMain;GameApp.Runreads them the same way. --json. A normal (non-development) run's summary has agameOptionsobject with the declared options that were given, for scripts to check.- A game that needs its options before an instance exists (to build its definition) reads the
argsofMainitself; it need not strip them out before callingGameApp.Run.