Achievements by Juhana Leinonen


Chapter: Setting up

We must define the following table in the story source:

Table of Achievements
achievement     description     validation     awarded
"Example"     "You've unlocked the example achievement"     example achievement rule     false

The "achievement" column is the name of the achievement, and the "description" column is the longer explanation of the achievement, usually the reason for why the achievement was awarded.

The validation column should contain a rule that succeeds when the achievement should be awarded.

This is the example achievement rule:
     if the player is carrying the MacGuffin:
         rule succeeds.

The rule doesn't need to check if the condition is true for the first time, the extension awards each achievement only once.

The validation entry can also be left blank. In that case the achievement must be awarded manually (see the next chapter).

The last column, "awarded", tracks whether the achievement has already been awarded. It should start out as false (unless for some reason we want the player to start the story with achievements already awarded).

Chapter: Awarding achievements

The rules in the validation column are checked at the very end of every turn and any new achievements are awarded. Achievements can also be awarded manually at any time:

award the "Example" achievement;

Adding the "silently" modifier to the phrase suppresses the achievement notification:

award the "Example" achievement, silently;

The rule responsible for achievement notifications is the print achievement unlocked rule, so unlisting it will remove notifications altogether.

Printing achievement text is an activity and rules can be attached to it like to any other activity:

Before printing the achievement text:
     say "Drumroll please..."

Chapter: Persistent achievements

The achievements can optionally persist between playthroughs by applying a use option:

Use persistent achievements.

Any unlocked achievements are then saved to a file and restored from there when play begins.

Persistent achievements works only in Glulx.

Example: * Another Day at the Office - Rule-based and manually awarded achievements

"Another Day at the Office"

Include Achievements by Juhana Leinonen.

Office is a room. "It's another boring afternoon in the office."

The desk is in the office. The inbox is on the desk. The memo is in the inbox.

A piece of gum is a thing.

The time of day is 4:57 PM.

Instead of looking under the desk for the first time:
     say "Hey, someone stuck a piece of gum under the desk!";
     now the player is carrying the piece of gum.

After examining the memo:
     say "It's from the boss. You forget it as soon as you've read it.";
     award the "Diligent Employee" achievement.

Table of Achievements
achievement     description     validation     awarded
"Desk Treasure"     "You found the piece of gum."     gum achievement rule     false
"Diligent Employee"     "You read the memo."     --     false
"Overtime"     "Stayed at work past 5 pm."     overtime achievement rule

This is the gum achievement rule:
     if the player is carrying the piece of gum:
         rule succeeds.

This is the overtime achievement rule:
     if the time of day is greater than 5:00 PM:
         rule succeeds.

Instead of exiting:
     say "Ok, that's enough for today.";
     end the story finally.

Test me with "read memo/look under desk/z/z/exit".