Love gaming, read game lit and want to learn about the games industry? Join Edwin's Group
YES PLEASE!

Last time we learned how to create conditional options. They’re handy for seeing which parts of your story the player has visited, and for adjusting the story to account for the player’s journey so far. But they’re not great at tracking states across the length and breadth of your interactive tale.

For instance, how do you manage basic RPG staples like Health, Gold and Magic Points?

To play the short example I've created to demonstrate how Ink can track magic points, click here. The game should open up in a new window for you. It's the working version of the example I talk about below. :-)

Variables

I’m in a Harry Potter mood today so let’s go with Magic Points as our variable of the hour.

First we need to tell the engine that we have a Variable that’s going to track our player’s reserves of magic energy.


VAR MAGIC = 0


We put that right at the top of our script, where the engine will see it before anything else. Then we start our game with a Divert and a Knot.


-> SPELL_CAST

=== SPELL_CAST


Let’s give our player some magic points to play with, since their total is currently zero.


~ MAGIC = 10


The player now has ten magic points. But how about some spells and a reason to cast them?

 

While you have nothing personally against orcs, being sapient bipeds just like yourself, this one seems intent on cutting your head off with his scimitar.

You have three spells you could cast and {MAGIC} magic points left.

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

    -> MISSILE_SPELL

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

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE


 

Okay, let’s unpack what I’ve just written above.

You have three spells you could cast and {MAGIC} magic points left.

By putting {MAGIC} we’re telling the engine to display the number currently stored in the MAGIC variable. Thanks to ~ MAGIC = 10, that number is now 10.

 

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

    -> MISSILE_SPELL

 

{MAGIC >= 5} means that if the MAGIC variable holds a number that’s equal to or greater than 5, the player will be able to cast a Magic Missile spell that costs 5 magic points.

 

The Magic Missile option will be displayed when there’s 5 or more magic points in the player’s reserve and will vanish (be hidden by the engine) if the player’s mp reserve is less than 5.

But let’s say the player has enough mp to cast Magic Missile. What then?


 

= MISSILE_SPELL

~ MAGIC = MAGIC - 5

A gleaming arrow of energy shoots from your hand and explodes against the orc's armor. It doesn't even slow him down!

You have {MAGIC} magic points remaining.


 

By using ~ MAGIC = MAGIC - 5 we’ve reduced the player’s magic reserve by five.

You have 5 magic points remaining.

 

The player now only has enough mp to cast one more spell. Which one will it be?

 

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

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE


How about we put this angry orc baby to sleep?


= SLEEP_SPELL

~ MAGIC = MAGIC - 5

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}[Sleep (5MP)]

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE


Uh oh! Thanks to ~ MAGIC = MAGIC - 5 the player is now totally out of magic points! That means neither of the top two options will be displayed by the engine because MAGIC is not greater than or equal to 5.

You have 0 magic points remaining.

That leaves only this option for the player to select because of {MAGIC < 5}


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

    -> SCREAM_DIE


If MAGIC is less than 5 it’s time to SCREAM FOR MERCY!!


= SCREAM_DIE

You raise your hands and scream for mercy. The orc obliges by painlessly removing your head.

Let's have another go at this, eh?

+ [Back to the start.]

-> SPELL_CAST


How does the player WIN this scenario?


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

    -> INVISIBILITY_SPELL

 

= 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 quietly sneak away and escape.

CONGRATULATIONS! You have survived to cast another day.

-> END


 

Even if the player chooses to cast Sleep or Magic Missile first they’ll still have 5 left over to cast Invisibility. 

But two strikes and I’m afraid they’re out. ;-)

Here’s the Ink script for this game in its entirety so you can see how it all works together.


 

VAR MAGIC = 0

 

-> SPELL_CAST

 

=== SPELL_CAST ===

~ MAGIC = 10

While you have nothing personally against orcs, being sapient bipeds just like yourself, this one seems intent on cutting your head off with his scimitar.

You have three spells you could cast and {MAGIC} magic points left.

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

    -> MISSILE_SPELL

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

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE

    

= MISSILE_SPELL

~ MAGIC = MAGIC - 5

A gleaming arrow of energy shoots from your hand and explodes against the orc's armor. It doesn't even slow him down!

You have {MAGIC} magic points remaining.

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

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE

 

= 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 quietly sneak away and escape.

CONGRATULATIONS! You have survived to cast another day.

-> END

 

= SLEEP_SPELL

~ MAGIC = MAGIC - 5

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}[Sleep (5MP)]

    -> SLEEP_SPELL

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

    -> INVISIBILITY_SPELL

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

    -> SCREAM_DIE

 

= SCREAM_DIE

You raise your hands and scream for mercy. The orc obliges by painlessly removing your head.

Let's have another go at this, eh?

+ [Back to the start.]

-> SPELL_CAST


As you’ve likely gathered already, you can utilize that MAGIC variable across the entirety of your game. Let’s say the player drinks a magic-replenishing potion or has a good night’s sleep and is rejuvenated by the light of the moon.

~ MAGIC = 10

And what if the caster has her spells and a magic wand she can use?

We’ll explore how Variables can interact with each other in the next tutorial.

 

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!