All examples · Scenes · As Markdown, for AIs

Scenes with props

What this example shows

A scene takes props, like a component: how it is opened, given by whoever opens it. The menu opens the level it has chosen with scene.change(Level, { props: { level } }), and the level goes back with scene.change(Menu, { props: { chosen: level } }), so the menu does not start on the first one again. Given the function, TypeScript checks the props: { levle: 2 } does not compile. By name, scene.change('Level', { props: { level } }), it works the same, unchecked.

Every prop has a default, ({ level = 1 }: { level?: number }), because a scene also starts with none: the menu is the first scene and nobody gives it anything, and the editor's Play starts any scene on its own. What stays true across scenes, lives or coins, is a store; how this one opens is a prop. ◀ ▶ choose, X plays, Z goes back.

Starting
Starting
—