Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Adding additional sidebar elements

edited November 2015 in Help! with 2.0
I'm using Sugarcube with V2 of Twine (online at the moment).

I've seen some games using this template, that have other elements in the sidebar, such as the location and/or time of day.

How would I do this? Not necessarily those elements, but I would like to know how to add things to the sidebar. I think it would be handy to show objects being carried, for example.

I'm guessing it requires complex scripting, which is where I'm pretty much stuffed as I know none of it.

[Edit] Okay, so I've discovered links can be added to the sidebar by adding a StoryCaption passage. Getting those links to do what I would like is still beyond me.

Comments

  • Clicking on a markup link in the StoryCaption area will navigate the reader to the target passage of the link.
    Getting those links to do what I would like is still beyond me.
    You will need to supply a lot more detail if you want people to explain how to achieve the results you want. lol
  • edited November 2015
    If you haven't already, now might be a good time to read the SugarCube 2 documentation.


    To add links, actual links only, to the UI bar you may use the StoryMenu special passage. As to how to make the links, they're usually either passage links or <<click>> macros (see: markup language and <<click>> macros). For example:
    [[You|PC Description]]
    <<click "Daily Planet">>/* ...do something... */<</click>>
    
    Just put each link on its own line.

    As a final note about UI bar links. They're commonly used to navigate to passages which provide character descriptions, inventories, journals, etc. Doing so, obviously, navigates the player away from the story. So, to get the player back to the proper place within the story, you'll probably need to use the <<return>> macro, if the visited passage alters state, or the <<back>> macro, if it does not—there are other methods you may, or may have to, use depending on the the complexity of your side passages (see: <<return>> macro, <<back>> macro, previous() story function).


    To add other, non-link content (e.g. stat displays), to the UI bar you may use the StoryCaption special passage. As to how to make displays of one sort or another, generally you simply place whatever it is you want to print there in the passage—either alone, if it's simply a $variable, or via the <<print>> macro, if it's more complex (see: naked $variable formatter and <<print>> macro). The reason that works turn-to-turn is that most of the special passages are processed each turn ("turn" here meaning each time the player navigates a passage). For example:
    | !Time:|&nbsp;|$time |
    | !Loc.:|&nbsp;|$location |
    | !Caps:|&nbsp;|$bottleCaps |
    
    I used a wiki table there to make things align nicely, but you get the idea, I hope. You may use whatever markup you wish there (SugarCube's wiki markup or HTML).
  • Thanks to you both for the replies.

    greyelf, I was thinking the exact same thing as I was writing the post, and almost added a line to explain I realised no one would be able to offer help unless I was more specific. I suppose I was sort of asking in preparation - in as much as I knew I would probably want to use side links / elements at some point, without knowing exactly what at this time.

    TME, I'm afraid I'm not familiar with macros, markup, and even less with scripting and java. I have a fairly good understanding of CSS, and a little html.

    For instance, I would now know how to add a link to an inventory, and how to send the player to that particular passage, but certainly not how to generate the inventory within that passage.

    Would the code to generate an inventory go in the passage itself, or a seperate code sheet somewhere, such as when adding CSS?

  • edited November 2015
    Jud_Casper wrote: »
    TME, I'm afraid I'm not familiar with macros, markup, and even less with scripting and java. I have a fairly good understanding of CSS, and a little html.
    First. JavaScript, not Java. Aside from the similarity in their names, they are separate languages which have very little in common.

    Second. You're going to have to learn, at least some of, the macros and markup. Most authors probably get by with no real understanding, or use of, JavaScript (unless they use Snowman, since that's all you get), so knowledge of JavaScript isn't mandatory. CSS knowledge will be useful—since, aside from basic markup like emphasis/strong/etc, all styling is done via CSS. HTML knowledge could also be useful—since, if desired, you may use HTML in preference of most of the wiki markup.

    Jud_Casper wrote: »
    For instance, I would now know how to add a link to an inventory, and how to send the player to that particular passage, but certainly not how to generate the inventory within that passage.

    Would the code to generate an inventory go in the passage itself, or a seperate code sheet somewhere, such as when adding CSS?
    That would depend on what kind of "inventory" you're talking about. You can write an inventory in a number of different ways and that, naturally, affects how you'd go about generating it, displaying it, adding/removing items from it, etc.

    That said, you will likely have, at least, some code in the inventory passage itself. If you're using some of the inventory macros which can be found around here, then you may simply have a few macro invocations. If you're doing more of a key item type inventory, then your inventory passage might consist solely of a number of <<if>> macros.
  • I feel awful having to keep clicking the 'no' option when asked if a post answered my question, but I keep getting pop-up reminders to choose one of the two.

    Anyway, am I correct in thinking that the <<if>> macros would be used in conjuction with variables elsewhere?

    I think I need to study the tutorials as I don't even know how to add variables, but the one thing I find with tutorials for things like this, is that while they explain the code itself, they never explain where the code goes.
  • Jud_Casper wrote: »
    Anyway, am I correct in thinking that the <<if>> macros would be used in conjuction with variables elsewhere?
    That is correct, yes.

    For example, let's say you initialize some key item $variables in StoryInit:
    <<set
    	$hasAtticKey   to false,
    	$hasBattery    to false,
    	$hasPoisonVial to false,
    	$hasRustyKnife to false
    >>
    
    Then you might show that the player has, or does not have, them in your inventory passage, like so:
    You have:
    <<if $hasAtticKey  >>Attic Key — Probably unlocks the attic door.<</if>>
    <<if $hasBattery   >>9v Battery — Might be useful, if you find something that runs on a 9v.<</if>>
    <<if $hasPoisonVial>>Poison Vial — You found this in Ms. Marple's spice rack.<</if>>
    <<if $hasRustyKnife>>Rusty Knife — Just a rusty butter knife.<</if>>
    
    You'd set them to true in other passages. How you'd go about that depends on you, really—could be automatic in some cases, could require the player to choose to take the item in others, etc.

    Jud_Casper wrote: »
    I think I need to study the tutorials as I don't even know how to add variables, but the one thing I find with tutorials for things like this, is that while they explain the code itself, they never explain where the code goes.
    In the case of the Twine story formats, that would likely be because where the code goes depends largely on what you're doing. The notable exceptions to this, where the code mostly/always goes into the same place, are (for Twine 2):
    • JavaScript should mostly go into the Story JavaScript (story menu > Edit Story JavaScript).
    • CSS should mostly go into the Story Stylesheet (story menu > Edit Story Stylesheet).
    • Story initialization code (e.g. $variable initialization) should go into the story format's initialization passage, if it has one (e.g. SugarCube has the named passage StoryInit, Harlowe has passages tagged with startup).
  • edited November 2015
    So, I create a new passage and title it StoryInit, and then in the main body field (where location descriptions usual go) I would insert those variables examples you set up?

    Then after this, I set up another passage and call it Inventory (linked to from the sidebar) and add the conditions you posted?

    But then when I set up a regular location passage that includes an item the player can take, how do I code that?

    i.e
    You are in the shed. There is an axe here.
    
    [[[Take axe]]
    

    I'm sure it's not as simple as that, is it?
  • Jud_Casper wrote: »
    So, I create a new passage and title it StoryInit, and then in the main body field (where location descriptions usual go) I would insert those variables examples you set up?

    Then after this, I set up another passage and call it Inventory (linked to from the sidebar) and add the conditions you posted?
    That is correct, yes.

    Jud_Casper wrote: »
    But then when I set up a regular location passage that includes an item the player can take, how do I code that?

    i.e
    You are in the shed. There is an axe here.
    
    [[[Take axe]]
    

    I'm sure it's not as simple as that, is it?
    First. You have too many left square brackets here on [Take axe.

    And whether it's that simple or not is up to you. I mean, yes, you do need more than what you've shown, but it could be nearly that simple.

    For the following examples I'm going to use Twee notation (i.e. :: Passage Name)—you can't use this with Twine, but it makes a decent notation for examples.

    You could, for example, do something like the following:
    :: Shed
    You are in the shed.<<if not $hasAxe>>  There is an axe here.  [[Take it?|Take axe]]<</if>>
    
    [[Leave the shed|Backyard]]
    
    :: Take axe
    <<set $hasAxe to true>>\
    You pick up the axe.  It seems reasonably sturdy, though you note the blade is somewhat rusty.
    
    [[Return|Shed]]
    
    That allows you to add extra detail for the axe, but it also adds an extra state to the history that you don't really need.

    Alternatively, you could something like the following instead using a setter link:
    :: Shed
    You are in the shed.<<if not $hasAxe>>  There is an axe here.  [[Take it?|Shed][$hasAxe to true]]<</if>>
    
    [[Leave the shed|Backyard]]
    
    There is currently an issue with Twine 2 where it mishandles setter links a bit. As a workaround, you could write the above using the <<click>> macro:
    :: Shed
    You are in the shed.<<if not $hasAxe>>  There is an axe here.  <<click [[Take it?|Shed]]>><<set $hasAxe to true>><</click>><</if>>
    
    [[Leave the shed|Backyard]]
    
  • So using one of the above, would mean that 'Axe' would then be listed when I went to the inventory page?
  • edited November 2015
    Whoa! I tried it and it worked! *



    * once I'd remembered to change the inventory code to 'if $hasAxe;' from the example you provided.
Sign In or Register to comment.