Several beginner's questions (SugarCube)

Twine Version: The online editor at twinery.org? (I’m on mobile)
Story format: SugarCube 2.37.3

Hello, so I recently started to learn programming by trying to make a game in Twine with the online editor because I only have a mobile, and I have several questions, so if that’s alright I’m gonna list them. I hope I can express them in a way that makes sense :face_with_tongue:

  1. The main thing I am trying to do right now is reuse series of passages. My current project is organized as a series of bottlenecks that branches all come back to. Before and after those bottlenecks I have unique events that move the plot forward, but in the middle I have events that repeat themselves, with choices that will cause display variations in the story. So basically I have events with their own branching that I want to reuse regularly, and sending the player to a part that’s previously written is easy enough, but it’s the bringing them back to the right bottleneck that I’m not sure how to achieve? I’m guessing I’ll need a variable to keep track of how far the player is into the story, but how do I make that change the passage targeted in the return link?
  2. Placement of consequence variables: Before, during or after events? This is more of a general question on best practices I guess. I feel like it makes more sense to put these variables right in the event they are related to (for example setting a $metCharacter right at the end of the paragraph that describes the player meeting someone, in the middle of the passage), but are there considerations I should keep in mind? I know it can also be applied on the link that leads to a passage. Are there pros and cons to either approach?
  3. In case of a choice where all options go back to the same passage afterwards, is it better to create separate passages for each, or to handle it in the original passage with a replace and display variations, or display variations in one dedicated passage? Generally speaking do you prefer to have more passages or more display variations?
  4. Setting variables as false in the StoryInit and unsetting them as they become true vs. setting them as true as events happen and keep track of them from there? Here I am more specifically thinking of variables such as $metCharacter or $visitedPlace. I’m still trying to grasp what is and isn’t appropriate to put in the StoryInit and I’m also trying to make sure I learn good habits from the start and unsetting variables that no longer serve seems like one :face_with_tongue:
  5. Tags on passages? So if I understand correctly, these can be used to apply different style sheets, but since I’m not worrying about those for now in the meantime I’m using them to keep track of thing I’ll need to come back for when things have progressed more, or tasks I want to lump together. For example I’m tagging passages where I’ll want to use a specific variable once my project is fleshed out enough that I’ll be able to know what kind of math I want to subject it to, or passages to which I need to come back to to code things, or the ones where I left a hole in the writing etc. So it’s a temporary use of tags, but are there things I should look out for, or better ways to proceed?
  6. And finally, what is a .twee? When I try to look it up I find things I don’t fully understand about files created with Tweego, but I don’t use that tool, and the online editor has a button to export the project as a .twee file. What does it do and would I be able to use it as a mobile user?

Hi there! Welcome to using Twine :smiley: I’ll do my best to answer the questions in the same order.

1

There’s no “one true way” about structuring a series of passages, but there are some best practices that might help here. Generally you only want a distinct passage when it’s text is entirely different, so your instinct to reuse passages is good. You can use a story variable to track where you have been, or use the visited() function to check some past passage.

e.g. imagine a pair of routes. They start at A and B, both go through C and then end up and D and E respectively.

A --+        +--> D
    |--> C --|
B --+        +--> E

You can set a variable in A and B to say where you started and then check that in the outward link from C

:: A
<<set $ab_route = 'A'>>

:: C
<<link "Proceed" $ab_route>><</link>>

Alternatively you can do the same with visited()

:: C
<<set _target = visited("A") ? "A" : "B">>
<<link "Proceed" _target>><</link>>

What you should not be doing is using <<return>>. <<return>> just sends you back to the previous passage, it’s not smart enough to manage this sort of structure.

2

If at all possible, you should place variable changes inside links, because if you place them straight in the passage, then re-visiting that passage will make the change again. Not so bad if it’s just true/false but a real pain if it is $money += 10.

Instead of that, make your changes in the link leading two or from the passage.

<<link [[Get Cash!]]>><<set $money += 10>><</link>>

3

This is more a matter of taste, but I always prefer variation over multiple passages. It’s so easy to end up making a change in one variation and forgetting to do it in another.

4

If you don’t set things in StoryInit and then refer to them later, you will likely get an error. That’s not to say “don’t do it”, but to say that if you don’t, you have to be more careful.

I like to have a single $events variable as an object and put each event as a property on that. That way you don’t get an error if it isn’t set.

:: StoryInit
<<set $events to {}>>

:: some passage
<<set $events.metJoe = true>>

Of course you can still initialise them in StoryInit

:: StoryInit
<<set $events to {
  metJoe: false,
  metTom: false
}>>

:: some passage
<<set $events.metJoe = true>>

5

Tags on everything! Tags identify meta information about passages. You can use them for yourself as markers and notes. You can target them with CSS styles, you can check if the current passage has a tag with tags().includes("tag name") you can get all the passages in your story that have a certain tag with Story.find() and Story.filter().

6

Twee is a plain text format for representing a Twine game. It’s what I’ve been using for my examples here. A passage in Twee looks like this:

:: Passage Name [tags] {position}
Text

You can export your game as twee and spellcheck it, then import it again, or use it in other tools (like tweego to turn it into a playable file, twee file splitter to group related passages together, gordian book to turn it into a choose your own adventure book, etc.)

I think there may be a mobile twee editor out there, but I’m afraid I don’t know the link. However, since a twee file is just plain text, you can edit it in any plain text editor your phone might have.

3 Likes

Thank you so much for taking the time to answer everything in so much detail! I’m very grateful!

Yes! This is exactly what I’m trying to do. Thank you for the two alternatives! So if I understand correctly, when you write the link leaving C instead of a passage name you use a variable that contains it? So far the vast majority of my links look like

[[Text that make up the link|Name of passage][Code if something needs to happen when clicked]]

So instead of putting “name of passage” I’d put the variable that keeps track of progression?

  1. That makes sense. I haven’t done any kind of wallet system yet (I don’t plan to for this first project), but I will have a numerical variable running through during the story and yes my instinct was to put it with the link.

  2. That too makes a lot of sense! I haven’t done nearly enough variations to imagine this could be a problem yet, thank you for the heads up! It does sound like keeping things together would make it easier to work with and keep things neat.

  3. Now this is a way to use variables that I have yet to learn! :joy: I’ve seen this in other people’s codes without understanding what it did, but now thanks to your answer I have context that will make it much easier. And here I was making individual variables and starting to ponder how to organize it all :joy: Now I have a much clearer idea of what my StoryInit needs to look like!

  4. Oooh, thank you! Lots if possibilities!

  5. And thank you for this explanation!

I’m excited to return to my project and try all this. Thank you so much!

For your “links that set variables” you have a number of different formatting options, and they mostly depend on how complex a thing you need to do.

The basic link syntax [[link|to passage]] can set a variable, like this:

[[link|to passage][$variable to value]]

You can even set a couple of variables (I think, I’ve never done this)

[[link|to passage][$a to "b";$b to "c"]]

And yes, you can also substitute a variable for some part of the link as well:

[[_link_text|_passage]]

However doing this creates fake passages in Twine that you don’t want, because Twine doesn’t know what _passage is, and will make a passage called _passage instead of whatever you want your variable to be.

So a better approach to variable passage links is to use the <<link>> macro:

<<link _link_text _passage>><</link>>

That won’t make a link on the passage map, but it also won’t make a fake passage you need to delete. The <<link>> macro can also run any sort of code inside it, not just setting variables.

<<link "Jump!">>
  <<if random(1,2) == 1>>
    <<goto "fall">>
  <<else>>
    <<goto "reach the other side">>
  <</if>>
<</link>>

Way more possibilities than [[link]] offers.

One other thing to note. If you really like the passage links on the map (I know I do) you can also use [[]] inside a <<link>> (<<link [[passage]]>>) and if there’s just a simple choice of routes you can use an <<if>> to have two links (and therefore two arrows).

<<if visited("A")>>
  [[Continue|D]]
<<else>>
  [[Continue|E]]
<</if>>
1 Like

Wow thank you! All of this is incredibly helpful!