the absolute beginners guide to twine part i
I've posted this in the tutorial channel in our decoding twine server, but I figured it might be helpful to keep on here. As someone who found learning twine incredibly daunting especially with so many things to read, often using coding language I was expected to already understand, I want make coding in twine alot simpler for beginners.
So, with this, I'm unleashing the absolute, absolute, begginers guide/series of sorts for people looking to pick up twine, but might be intimidated. Here I'm talking about the 'stuff you should already know' 🙄 you see when going into tutorials. I really hope some of this helps, and I'll be happy to answer any questions I can in the future, or at least, send you to someone else who can too.
so, with that being said, here's the absolute beginners guide to twine, part i
So, this is the most basic basic basic stuff you're going to use within sugarcube twine, that I thought would be helpful for those of us who are just learning, there are plenty of more in depth guides out there, but I wanted to keep this as simplistic as possible in a sort of explain-to-me-like-i'm-five style.
Once you've gotten twine installed and switched your format over to sugarcube -> (This is done by opening up a new project, clicking in the bottom left of your screen with your game's title, and clicking on the 'Change Story Format' Option and switching over to the latest version of Sugarcube (sugarcube2.36.1))
PASSAGES These are what hold the content of your story! They hold your main body of text and LINKS which what connect passages in your story. Think of passages as pages in your choose your own adventure novel, and links are the choices that tell you (or the program) which page to flip to. Passages have TITLES and BODIES Your Title, is you guessed it, what your passage is called. This will not show up in game, but I'd recommend naming your passages something bland incase code-divers hop in and look at your code lest they find something embarrassing in your titles. Your body, is what is in the actual passage itself, this is what shows up in game and contains links.
LINKS links are what tie ALL of twine together across the formats, and in sugarcube you can style them a series of ways, connecting one passage to the next. The easiest way to include a link looks like this: [[LINK]] This is a link that will appear as the word 'link' in-game, and will take you to the next passage entitled LINK. For this route, it's necessary to wrap your link in two sets of brackets OR [[]] These, which will actually make it function as a link. [[NEXT | LINK]] This is another approach you could take, where players will click on a link that says "NEXT" in game, but will take the player to a passage called LINK. For beginners think, left is what will appear to the player and right is the title of the passage just for you the developer.
USING VARIABLES - variables are an incredibly useful tool that can be used to keep track of things throughout your game, whether that be your character's name, whether or not the player's visited a passage, the response to a question or numerical stats.
For our purposes there are three types of variables, Boolean (true/false), Numerical, and String Variables.
The two macros that will be useful in reference to variables are: <<set>> and <<if>>
First things first, when you have your list of variables ready, you're going to want to define them first in the StoryInit Passage. This is the first passage that will run in your game, you won't see it when the game is played BUT it does get run in the background behind everything else. By setting your variables ahead of time and modifying them later it allows for a smoother run through of the game that eliminates problems further down the line. You can of course, define your variables as your game progresses in individual passages BUT you might run into trouble later down the line.
So, let's set up your variables in a mock StoryInit Passage here: :: StoryInit <<set $characterfriendship to 0>> <<set $yesornoanswer to false>> <<set $eyecolor to "null">>
SO, what this does is it sets a variable called $characterfriendship to 0 using the <<set>> macro. What this does is set my friendship points with said character to ) that can progressively grow throughout the game.
VARIABLES whatever you call them ALWAYS have to be proceeded by a dollar sign ($) for them to function in game, and you can format the <<set>> macro a number of ways. For example: <<set $characterfriendship to 0>> <<set $characterfriendship = 0>>
Both will function the same and make it so that variable will equal 0.
Now moving on, if we want to alter those numerical values further down the line in a passage we can do so in a number of ways, whether that be adding, subtracting, dividing or multiplying. For example if I want to ADD 1 point to my friendship my code would look like this. <<set $characterfriendship += 1>> OR IF WE'RE JUST ADDING ONE you could simply do this: <<set $characterfriendship ++>>
To subtract you'd do: <<set $characterfriendship -= 1>> To multiply you'd do: <<set $characterfriendship *= 1> To divide you'd do: <<set $characterfriendship /= 1> This of course can be altered to any number, just by changing that 1 to the number you'd like.
BOOLEAN VARIABLES are useful when an option has two outcomes, helpful for things like yes or no questions or passage visits. Setting those variables looks something like this:
<<set $yesornoanswer to false>> <<set $yesornoanswer to true>>
when setting the variable it is NOT necessary to add quotations around the words true or false, this will mess up your work down the line if you don't continuously use those quotes again.
STRING VARIABLES These are helpful for options with more complex outcomes, things like multiple options, names, or character customization.
<<set $eyecolor to "null">>
So far in StoryInit I've only set it to null because I haven't set it yet in-game, and by setting it to "null" it just gives me an option that isn't really an option.
SETTING VARIABLES WITH LINKS SO, moving forward, no that I have defined my variables in StoryInit, I want to change them when I'm in game.
You could do this of course, by setting them at the top of your passage in game. So looking something like this:
::passagethree <<set $eyecolor to "brown">> Her eyes were brown. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
But another sometimes more effective way to set them with actual links! You can go about that a couple of ways.
One is with the brackets method and it'll look something like this.
[[BLUE | LINK][$eyecolor to "blue"]]
Using this method, it's important NOT to include the word set, simply skipping ahead to your variable the to and what you're defining it as.
The other method is through the <> method. This is simply another way to style your links. I like the brackets method, but it's all up to you.
<<link 'blue' 'passage-four'>><<set $eyecolor to "blue">><</link>>
The first quotation (blue) is what the player will see as the link in the passage, and the second quotation (passage-four) is what the associated passage is called. You can set the $variable within those <<link>>













