Learning Ink: Part 10: Lists

InkLogo

 

Learning Ink

 

Ink is a scripting language for creating interactive fiction like choose-you-own-adventures and other vast, branching stories.


 

Lists

Along with variables and their different types like temporary and constants, Ink also has a storage type called a list. Acting like an array in other programming languages, a list allows for storing a sequence of things.

Rules for Lists:

  • Must contain unique variable names
  • Ordering matters
  • Positions start with 1 (unless overwritten)
  • Will create variables if they do not already exist
  • Created variables are set to false

Because lists will create new variables if included and not previous created, this allows for creating a list of possibilities and then having a new, separate variable with the current state.

Screenshot 2018-08-11 15.25.25

Variables using a value from the list can also be changed and used in other places.

Screenshot 2018-08-11 15.26.39

These can also be used as part of the flow once set earlier, allowing for changing states throughout a story.

Screenshot 2018-08-11 15.31.01

For dealing directly with lists, Ink also has specific functions:

  • LIST_COUNT():  The number of true entries
  • LIST_MIN() The first true entry
  • LIST_MAX(): The last true entry
  • LIST_ALL(): All entries, separated by commas
  • LIST_RANGE(list_name, min_value, max_value): A selection of the list based on its name, the starting value, and the ending value
  • LIST_VALUE(): The numerical value or, if not set, the position in the list starting at 1
  • LIST_INVERT(): Changes values to their opposites (i.e. changes Booleans from true to false)

Ink also has the ability to test for inclusion:

  • ?: If multiple entries are part of the list and true
  • has: If an entry is part of the list and is true
  • hasnt: If an entry is not part of a list and not true
  • !?: If multiple entries are not part of the list and not true

GitHub Gist Version:


CONST name = "Dan"
VAR fretCount = 0
VAR freakOutCount = 0
LIST possibleFeelings = happy, fretting, anxious, panicking
VAR feeling = happy
It was a {weather()} {dayOfWeek()}.
I was unsure about asking him out on a date. We had known each other for over six months, but I couldn't work up the nerve. I knew he was single, we got along great, but… what if he turned me down? Or was straight? Dating in the workplace had never worked out for me. But he was cute! And we got along! But I just wasn't sure.
(I'm such a nervous wreck!)
CHAPTER 1: ASKING HIM OUT
-> Chapter_1
=== Chapter_1 ===
{&(What should I do?) | (What if I didn't say anything?) | (Should I ask him out?) | (Maybe I should move to another city?)}
+ [(Did he even like guys?)]
~ fretCount++
-> Chapter_1
* [I should just do it!]
I let it go for weeks and weeks. I kept seeing him in the office. We'd smile — well, I'd smile and sometimes he'd smile back. (I lived for those smiles.)
{
fretCount > 2:
After thinking about it multiple times, I finally asked him out.
~ feeling = fretting
fretCount < 2:
Finally, I asked him out, and he accepted with a smile!
~ feeling = happy
}
CHAPTER 2: GETTING READY
Why hadn't I thought about what I was going to wear?
Here I am, 30 minutes before the date and I haven't picked out my clothes!
* (Look_Good) [Pick out something good.] I took some time and picked out something good.
* (Random_Clothes) [Don't bother.] I just grabbed some clothes off the floor and ran out.
Finally, I was ready.
CHAPTER 3: EATING DINNER
He greeted me at the door of his apartment. {Look_Good: "You look good, {name}!"}{Random_Clothes: "Ready?"}
But I hadn't made dinner plans! And they we were, standing outside his apartment.
He turned to me. "What should we eat?"
-> Pizza_Choices("")
=== Pizza_Choices(previousChoice) ===
{previousChoice != "": (We just talked about about having {previousChoice}.) }
* [Pizza?] He shook his head. "I don't like pizza."
-> Freak_Out ->
-> Pizza_Choices("pizza")
* [Salad?] "Not a salad."
-> Freak_Out ->
-> Pizza_Choices("salad")
+ [Nothing?] {"We have to eat something!"|"Stop being silly, {name}!"}
-> Pizza_Choices("nothing")
* [Sushi?] "Sushi sounds good!"
We walked to the local sushi place.
<- Food_Choices
-> END
=== Food_Choices ===
The place was only moderately crowded and we made our way over to a table. After getting our menus, I pondered my choices: sashimi, makizushi, ramen, tempura, and, of course, sushi.
"How are you feeling?" he asked.
"I'm… {feeling}?"
"Oh? What are you {feeling} about?"
-> DONE
=== Freak_Out ===
(Did I freak out over getting the food choice wrong?)
+ [No]
(I didn't freak out.)
->->
+ [Yes]
~ freakOutCount++
{
freakOutCount > 2:
I was so stressed out that we ended the date early!
~ feeling = panicking
-> END
else:
(I freaked out a little bit, but I kept it under control.)
~ feeling = anxious
->->
}
=== function dayOfWeek() ===
~ return "{~Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday}"
=== function weather() ===
~ return "{~sunny|rainy|clear|cloudy}"