Keeping track of Active Quests

Twine Version: 2.3.9
Story Format: Sugarcube 2.31.1

I’m making my first Twine game which will have different missions/quests. Inside the StoryCaption I want to print out which Quests are active right now so the player can easily keep track of what to do next.

The game moves between 4 time passages(morning, day, evening and Night. The night passage only has code and sends the players insantly to the morning passage using the <> function. Inside the Night passage I include all the coding that needs to happen before the next day(i.e. <<Set $Days to $Days + 1>>)

Since the Active Quests can change during the day (by completing questst) I set up a Quest updater inside the night passage that the player will pass through. All coding I’m currently using are mentioned below.

For the Quests I set up Objects Example below. All the Quests objects I create are labelled as followed: $Quest"Inside Number".

<<set $Quest1 = {
	"active": 1,
	"Completion": 0,
	"Progression": 0,
	"TimeRestriction": "True",
	"TimeLeft": 14,
	"Short": "Gather supplies by the side of the main road outside the forest.",
	"Long": "Drive towards the road to see if there are any supplies left. Maybe you can find some more food, or a tool that can help you along your way.",
	"Title": "Gather Supplies",
	"QuestTiming": 1,
	"Passage": "C1Q1P1"
}>>

I set the following Array:

<<set $Quests to []>>

<<if $Quest2["active"] is 1>>
	<<set $Quests.push($Quest2["Short"])>>
<</if>>

Which makes it possible for me to print out the information “ShortName” from the object $Quest1 mentioned above inside the StoryCaption using:

<<print $Quests[0]>>
<<print $Quests[1]>>

During the night cycle passage I have the following Quest Updater Code:

<<set $Quests.deleteAt(0,1,2,3,4,5,6,7,8,9,10)>>

<<if $Quest1["active"] is 1>>
	<<set $Quests.push($Quest1["Short"])>>
<</if>>

<<if $Quest2["active"] is 1>>
	<<set $Quests.push($Quest2["Short"])>>
<</if>>

The problem I run into is that I have to manually add code for every single $Quest"Number" I create. I am looking for a way to do this last part (setting the $Quest.push if Quest"Number" is 1) for every object I create (however many there will be). I am pretty much a beginner, please help me out by making the ansers not too complicated, thanks in advance!

1 Like

Personally I would restructure your data storage a little like the following…

<<set $quests to {
	"Q001": {
		"ID": "Q001",
		"Short": "Gather supplies by the side of the main road outside the forest.",
		"Long": "Drive towards the road to see if there are any supplies left. Maybe you can find some more food, or a tool that can help you along your way.",
		"Title": "Gather Supplies",
		"Passage": "C1Q1P1"
	},
	"Q002": {
		"ID": "Q002",
		"Short": "Visit Grandma's house.",
		"Long": "Travel through the dark scary woods to visit Grannie.",
		"Title": "Visit Grandma",
		"Passage": "Associated Passage Name"
	}
}>>
<<set $active to []>>
<<set $completed to []>>

…and then add the relevant ID to the $active Array when a ‘quest’ becomes ‘active’, and then transfer that ID to the $completed Array when the ‘quest’ is ‘completed’…

<<link "Visit Grandma">>
	<<run $active.push("Q002")>>
<</link>>

<<link "Leave Grandma's house and return home.">>
	<<run $completed.push($active.delete("Q002").first())>>
<</link>>

You can use the ID to lookup details about a specific quest in the $quest variable…

The title of the first 'active' quest is: <<= $quests[$active[0]]["Title"] >>

notes:
1: Obviously you can name the variables and the ID’s of the quests whatever makes sense to you & your project.
2: If the data associates with a quest doesn’t change once its been initialised then there is no reason to have that data stored in History or Saves, so I would move the definitions of the quests from a Story Variable to the special setup object.
eg.

/* Define the static 'quest' data on the setup object.. */
<<set setup.quests to {
	"Q001": {
		"ID": "Q001",
		"Short": "Gather supplies by the side of the main road outside the forest.",
		"Long": "Drive towards the road to see if there are any supplies left. Maybe you can find some more food, or a tool that can help you along your way.",
		"Title": "Gather Supplies",
		"Passage": "C1Q1P1"
	},
	"Q002": {
		"ID": "Q002",
		"Short": "Visit Grandma's house.",
		"Long": "Travel through the dark scary woods to visit Grannie.",
		"Title": "Visit Grandma",
		"Passage": "Associated Passage Name"
	}
}>>

/* ...and use the setup object when referencing information about a quest... */
The title of the first 'active' quest is: <<= setup.quests[$active[0]]["Title"] >>
1 Like

Fantastic explanation, thank you very much.

Will definetly restructure as per your first code suggests. Will think about using the Setup object function, first time hearing of it. Since the “Passage” information changes depending on the story progression and choices the player makes I’m guessing it’s impossible to setup the object and add information to it I can change. Will try both either way, got a long road ahead of me to figure this all out.

Thank you kind person for the quick answer!!

It’s strongly recommended that you do not change any information on the setup object (note that the name needs to be lowercase) during the playthrough of a game, since any such changes won’t be stored in the game’s save file, thus leading to potentially broken saves.

It’s best if you include any data which will never change on the setup object, since that will help prevent the game’s history from becoming bloated with redundant data, which will slow down saves, loads, and passage transitions. Similarly, data which is only used within a single passage should be stored in temporary variables (which start with “_”). Any other data which needs to be used across multiple passages must be stored in story variables (which start with “$”), so that they can be retrieved when a game is saved or loaded. You can also delete story variables when you’re done using them with the <<unset>> macro.

Basically, you can keep the unchanging parts of the quest data on the setup object, but any parts of the quests which may change while playing the game will need to be stored on a separate story variable.

Hope that helps! :slight_smile:

Another great response. Right now I am not using the setup object for anything, perhaps when performance starts becoming an issue I can start optimizing the game using this function.