GitHub Repo

Code for copy/paste

<stringname="page0">On your return trip from studying Saturn\'s rings, you hear a distress signal that seems to be coming from the surface of Mars. It\'s strange because there hasn\'t been a colony there in years. Even stranger, it\'s calling you by name: \"Help me, %1$s, you\'re my only hope.\"</string><stringname="page0_choice1">Stop and investigate</string><stringname="page0_choice2">Continue home to Earth</string><stringname="page1">You deftly land your ship near where the distress signal originated. You didn\'t notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.</string><stringname="page1_choice1">Explore the cave</string><stringname="page1_choice2">Explore the rover</string><stringname="page2">You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.</string><stringname="page2_choice1">Head back to Mars to investigate</string><stringname="page2_choice2">Continue home to Earth</string><stringname="page3">Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there\'s a very faint light up ahead.</string><stringname="page3_choice1">Refill at ship and explore the rover</string><stringname="page3_choice2">Continue towards the faint light</string><stringname="page4">The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren\'t far, but you don\'t know if your oxygen will last for a trip there and back.</string><stringname="page4_choice1">Explore the coordinates</string><stringname="page4_choice2">Return to Earth</string><stringname="page5">After a long walk slightly uphill, you end up at the top of a small crater. You look around, and are overjoyed to see your favorite android, %1$s-S1124. It had been lost on a previous mission to Mars! You take it back to your ship and fly back to Earth.</string><stringname="page6">You arrive home on Earth. While your mission was a success, you forever wonder what was sending that signal. Perhaps a future mission will be able to investigate…</string>

0:00

We have so much text in this story.

0:03

So many strings, which is why we should
put it all in our string resource file.

0:07

So, let's open up strings.xml again.

0:10

And we can start here at the bottom by
adding a new line and typing string name=.

0:17

And let's call this page0.

0:21

We could name our pages anything we want,
but when I wrote this story I mapped it

0:24

out like an array that starts at 0,
because that's how I was thinking of it.

0:29

We could call this page something
like start_page instead.

0:33

Really, what we want to do is pick
a consistent way to name things

0:36

that makes sense of the structure.

0:38

Let's stick with a page
followed by a number,

0:40

which matches up with our
finite state machine diagram.

0:44

Okay, so next I will paste in
the text of the page right here.

0:47

This text and all of the other
strings we will add are available for

0:51

you in the teacher's notes.

0:52

Okay, let's take a look at this string.

0:54

First, let's change it so
that the text wraps on the screen.

0:57

If we click on View and
then go down to Active Editor here.

1:00

We can click on Use Soft Wraps.

1:03

That makes it easier then
trying to scroll around.

1:06

So in the string, notice that I had to add
a lot of backward slash escape characters.

1:12

There are a lot of special characters,
especially that have to do with

1:14

punctuation like these single quotes and
double quotes.

1:18

And to put them in our
string resource file,

1:20

we need to use the backwards
slash to escape them.

1:24

Here you can see what happens if
we forget the backwards slash,

1:26

we should get a warning.

1:28

There you go.
It pops up.

1:29

And if we hover over it,
it says Apostrophe not preceded by \.

1:33

So, it's pretty obvious to see what
the error is and how to fix it.

1:36

There's also a special
sequence here at the end,

1:39

where we will plug in the user's name.

1:41

This is a string formatting sequence
that we will learn more about shortly.

1:45

So next, we should add the choice
labels for this first page.

1:49

I'm going to add a new string.

1:50

It's name will be page0_choice1.

1:57

And the first button will say Stop and
Investigate.

2:04

Then we'll do the same thing,
string name="page0_choice2".

2:11

And this button will say
Continue home to Earth.

2:16

Okay, rather than talk through
the rest of the pages,

2:18

which all have this same format,
let's do some more copying and pasting.

2:22

So, this code I'm pasting is available for
you to copy from the teacher's notes so

2:27

that you don't have to type it either.

2:29

I'm gonna add a few
spaces at the bottom and

2:31

make sure everything has
enough room on the screen.

2:33

And essentially what we've done is put the
text for each page into a group like this.

2:38

It doesn't matter that they're grouped
together or that they have spaces between

2:42

them, I just did that so I would know
how to find page 0, page 1, etc.

2:45

All right, so all of our text in our
story is now stored in this file.

2:49

This is a convenient place for
us to manage the text, but

2:52

remember that it's also useful if we ever
want to add additional string files for