Howdy, Stranger!

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

Temp variables in hooks

I'm using Twine 2.1.1 w/ Harlowe.

I have a temp variable called "_parser" that lives in a "header" passage. I want to use this to style certain lines of text that are meant to be in a "narrator voice" which talks to the reader, different from the regular text of the story.
(set: _parser to (text-colour: yellow))

I use this like so in passages, which works fine:
Jane pets her cat. _parser[Do you have cat?]

But when I try this:
_parser[You're going to love this part.]

[CONTINUE]<cont| (click-replace:?cont)[Jane pets her cat. _parser[Do you have a cat?]]

I get the runtime message "There isn't a temp variable named _parser in this place." Is there any way to get the inside-the-hook reference to the temp variable to know about the global one in the header? Is that the problem? Thanks for the help!

Comments

  • edited April 2017
    Why does it need to be a temp variable? If it's in a header-tagged passage, then it's essentially being carried into every passage anyhow, and at that point, you might as well use a normal story variable. Is there a specific reason it needs to be temporary?
  • Please state the name and full version number of the Story Format you are using, as answers can be different for each one. Based on the fact you are using a temporary variable I will assume you are using Harlowe v2.0.0

    You could get rid of the variable altogether and use CSS combined with a named hook to do the same thing. It will work in both situations and reduces the number of variables the system needs to track, it also makes it easier to add more complex styling to the parser's text if you choose to do so later.

    Add the following to your Story Stylesheet area:
    tw-hook[name="parser"] {
    	color: yellow;
    }
    
    ... the modify your passage contents to the following:
    |parser>[You're going to love this part.]
    
    [CONTINUE]<cont| (click-replace:?cont)[Jane pets her cat. |parser>[Do you have a cat?]]
    
Sign In or Register to comment.