- Understand the need for branching in programs.
- Practice branching with interactive stories in twine.
- Learn the syntax to create branching code in Python
All must Test a text based adventure, and create a short and simple adventure story using the Twine software on line (Level 5)
Most should complete the above, and create/adapt a simple branching program in Python. (Level 5)
Some could complete the above, creating a branching program in python without any help, using if/else and also nested if statements. (Level 6)
Words to learn: Selection, branching, if/else, nesting
We’ll start off with a game. Published in 1979, Zork was a tremendous success amongst students and people lucky enough to have access to a computer. The game is entirely text-based, as computers were nowhere near powerful enough to display graphics, showing different scenes. Zork was a combination of puzzle and fantasy adventure. By typing instructions in simple English, you should be able to find your way around the game.
In your book, jot down a couple of sentences giving your opinions of the game. Do you like it? Was it easy? Confusing? Did you achieve much in the time you had?
You’ll see that you were able to make choices based on the text you were given in the game. As such, the story is shaped around your decisions. The correct term for this is branching.
Click here to visit Twine. This is a wonderful tool for creating interactive branching fiction.
Click “Use it online” on the right-hand side, then the green “+Story” box also on the right.
Good. Now add this text:
I don’t know what went wrong. This started out as a pleasant evening stroll through the woods, but you must have taken a wrong turn somewhere. The light is fading quickly, and you’ve no idea where you are. There is a [[shady path to the left]], and you’re sure you can see some kind of [[flickering light ahead]].
Now close the text box and look. Where you added the square brackets, new story boxes have been created and given titles. If you click play, below, you can see that the first paragraph appears with hyper links, letting you navigate through the story.
- Continue with the story. Add as many story boxes as you can, and let your imagination run wild.
Improve your story:
- You can create links back to earlier parts of the story, by typing the name of any existing box between square brackets.
- Your link doesn’t have to be the name of the story box.
[[some text -> name of box]]
Lets you write something different from the name of the box you’re linking to.
- *Some text* will give you italics.
**more text** will give you bold.
<u>even more text</u> will underline text.
Back to Python
We’ll come back to Twine later, but for now we need to see how this fits in with Python.
When writing a program, we come to a point where we have to make decisions based on data and values within our code.
Now we’re going to write a program to check our timetable. Get out your planner, have a look at your timetable, and find a lesson you have on monday… put it into this code…
Run the program. So far, it asks you for a day of the week. If you type “Monday”, it’ll tell you one lesson you have that day.
**Note. If is always followed by a “condition” if this is true then the indented code underneath will run. If not, it won’t run, and the program will continue.**
So far, this isn’t much use. Our program only knows about one day of the week, and doesn’t respond to anything else. Let’s give it an error message…