bubblecode can prompt users for input with the ask command, making it easy to build interactive programs.
The ask command
ask displays a prompt and waits for the user to type a response. The response is stored in the variable you specify.
example.bubbleWhen running in the browser, the prompt appears as an inline input field. Type your answer and press Enter.
Combining ask with logic
User input can drive program flow just like any other variable.
example.bubbleBuilding a game
The ask command is the foundation for interactive games. Here’s a number guessing game:
example.bubbleHow it works in the browser
Under the hood, the bubblecode WASM runtime uses a replay model for interactive input:
- Your script starts running until it hits an
askcommand - The runtime pauses and shows the prompt
- You type your answer and press Enter
- The runtime replays the entire script from the beginning, feeding all collected answers in order
- This repeats until the program finishes
This means every ask re-runs the script — but it happens so fast you won’t notice.