Tutorial: the view of a world
Over nine steps you build the complete view of Treasure Island, a world that runs a small treasure hunt. The finished view draws the island from the data of the world, shows the conversation and sends moves, answers the questions of the world and turns the actions of its rules into buttons. It also lists who is in the world, follows the theme of the webapp, fits the screen of a phone and handles a page opened outside the webapp as well as a call that the webapp could not run.
What you will build
Walk North and then East until the world asks a question. Then press Ask for a hint and dig.
What you will learn
- Connect to a world and render it again on every change.
- Draw a map from the
dataof the world and update it while the person plays. - Render the conversation with the world and send messages on behalf of the person.
- Send a move, show its delivery status and offer Retry when it fails.
- Answer a question of the world with a form.
- Render the actions of the rules as buttons that call
act. - Show the members of the world, their roles and the role of the person.
- Follow the theme of the webapp and keep clear of the notch, the home bar and the on-screen keyboard of a phone.
- Handle two errors: (1) a page opened outside the webapp and (2) an action that the webapp could not run.
Before you start
The tutorial assumes the connection and the render loop of Quick start. Every step has a React version and a plain JavaScript version with the same behaviour.
The example of each step is a complete file that runs on a fake world defined in the same file without an account or a network. Any step can be copied into your project as a starting point. The React examples all import the useWorld hook that you copy once next to your components.
The steps
- Show the world: connect and render the name of the world and what is happening now.
- Draw the map: render the
dataof the world as a map of the island. - Talk with the world: render the messages and add a box for the text of the person.
- Make a move: send moves as messages and show their delivery.
- Answer a question: render a question of the world as a form that sends the answer.
- Offer the actions of the rules: render
now.actionsas buttons that callact. - Show the people: list the members, the roles and the role of the person.
- Fit the webapp and the phone: follow the theme and respect the safe areas and the keyboard.
- Handle errors and finish: handle a page opened outside the webapp and a failed action, then lay out the final view.
Next steps
Start with step 1: Show the world.