Learning Ink Script - Tutorial Eight

  • Edwin McRae

Last time we learned how to use a Variable in our interactive fiction to track magic points. But what happens when you have multiple variables to wrangle? What if the event we want depends on one variable being this and another variable being that at the same time?

Let’s take a look.

 

VAR MAGIC = 0

VAR LIGHTNING_ROD = false

 

See that Lightning Rod? It’s a type of magic wand in this story. And it’s also a boolean variable that can be either true or false.

Now let’s give our player some magic points and a Lightning Rod.

 

~ MAGIC = 0

~ LIGHTNING_ROD = true

The trick with a lightning rod is that it costs 5 magic points to use but magnifies a sorcerer's power so that the resulting lightning bolt does far more damage than your average magic missile. Yes, enough to kill our poor, unsuspecting orc.

Of course, since the lightning rod costs MP to use, we’ll have to test both that the player possesses the lightning rod and that they have enough MP to fire off a bolt.

 

+ {MAGIC >= 5 && LIGHTNING_ROD == true} [Lightning Bolt (5MP)]

    -> ELECTRIC_BOLT

Now the player can cast a Lightning bolt if their magic points store is greater than or equal to 5 and they possess the lightning rod.

 

“But aren’t they always going to have that lightning rod?” you ask.

 

Not if we add this…

 

Bear in mind that while Sleep is a very useful spell, it takes two hand to cast so you will need to drop your lightning rod and there won’t time to pick it up again.

 

And this…

 

= SLEEP_SPELL

~ MAGIC = MAGIC - 5

~ LIGHTNING_ROD = false

 

You drop the lightning rod gesticulate vigorously with both hands.

If he'd been a bored orc on guard duty, maybe this would've worked. But this is a charging orc with his blood up. IT'S NOT NAP TIME, MUMMY!

You have {MAGIC} magic points remaining.

+ {MAGIC >= 5}[Magic Missile (5MP)]

-> MISSILE_SPELL

+ {MAGIC >= 5}[Invisibility (5MP)]

-> INVISIBILITY_SPELL

+ {MAGIC >= 5 && LIGHTNING_ROD == true} [Lightning Bolt (5MP)]

-> ELECTRIC_BOLT

+ {MAGIC < 5}[Scream for mercy!]

 -> SCREAM_DIE

Therefore, if the player drops the lightning rod and casts the Sleep spell as their first choice, these will be their choices.

 

+ {MAGIC >= 5}[Magic Missile (5MP)]

    -> MISSILE_SPELL

+ {MAGIC >= 5}[Invisibility (5MP)]

    -> INVISIBILITY_SPELL

+ {MAGIC >= 5 && LIGHTNING_ROD == true} [Lightning Bolt (5MP)]

    -> ELECTRIC_BOLT

+ {MAGIC < 5}[Scream for mercy!]

    -> SCREAM_DIE

 

But “Scream for mercy!” won’t be displayed to the player because their remaining magic points are still equal to or greater than 5.

And “Lightning Bolt” won’t show up because LIGHTNING_ROD == false instead of true.

 

Btw, we need to add one more thing to make this update complete. What happens if the player shoots the orc with the lightning bolt?

 

= ELECTRIC_BOLT

~ MAGIC = MAGIC - 5

The lightning bolt strikes the orc dead center and conducts through his armor. The poor, steaming blighter is dead before he hits the ground.

CONGRATULATIONS! You have survived to cast another day.

-> NAVIGATION

 

Oh, and I never like to leave loose ends lying around… or dropped lightning rods for that matter.

 

= INVISIBILITY_SPELL

~ MAGIC = MAGIC - 5

Your body fades away like a bad dream in daylight. The orc roars with frustration and swings about wildly with his axe. With all the noise he's making, it's no problem to {LIGHTNING_ROD == false:pick up your lightning rod and }quietly sneak away.

CONGRATULATIONS! You have survived to cast another day.

-> NAVIGATION

 

Yes, you can also use variables to switch bits of text on or off, adding a whole new level of adaptability to your story. I personally love this feature because you can show the consequences of a player’s actions with a simple tweak of wording.

 

Okay, that’s it for this example. You can play a build here to see how the added variable affects the feel of the game.

But it’s important to note that we only had Ink check the state of two variables at once. Ink can actually compare as many variables as you want! And it can check variables in a variety of ways.

Equal to…

==

Does not equal…

!=

Greater than or less than…

MAGIC > 5

MAGIC < 5

Greater than or equal to / Less than or equal to…

MAGIC >= 5

MAGIC <= 5

This variable AND that variable…

MAGIC >= 5 && LIGHTNING_ROD == true

This variable OR that variable…

MAGIC >= 5 || LIGHTNING_ROD == true

 

And in the next tutorial we'll look at wrangling lots of different Variable states with LISTS. [COMING SOON]

 

For an example of my Ink Script work in full swing, you can download Guardian Maia Ep1 for free from Google Play and the Apple Appstore

You will guide a Māori warrior woman, Māia, on an interactive science-fiction adventure where your decisions mean life or death for your courageous heroine!

 

About Edwin McRae

Edwin is a narrative consultant and mentor for the games industry.

Share this post