Howdy, Stranger!

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

Sugarcube 2 - Replacing placeholder text

Hello, everyone. I'm currently working on my first Twine project as part of my Master's thesis. Although things are progressing nicely, I seem to have run into a snag.
<<nobr>>
<<set $location = "Woods [South] - Shack">>
<<set $roomWidth = 10>>
<<set $roomLength = 10>><</nobr>>
<<display "header">>
You pass through the [[door|woods1_entrance][$playerMoves +=1]] of the shack and scan your surroundings. The shack is <<print $roomWidth>> feet by <<print $roomLength>> feet. On the east wall, a small rusty <span id="shovel"><<click "shovel">></span><<replace "#shovel">>shovel<</replace>><<replace "#output1">>You pick up the shovel and put it in your backpack.<</replace>><</click>> hangs on a nail.

On the north wall, there is a small wooden table. On it, sits a <span id="lamp"><<click "lamp">></span><<replace "#lamp">><span id="keyItem">lamp</span><</replace>><<replace "#output1">>You pick up the <span id="keyItem">lamp</span> and put it in your backpack.<</replace>><</click>>.

<span id="output1"></span>

I've read TheMadExiles' post on a similar question, but what I'm wondering is can what I'm wanting to do be done?

For what it's worth, I've declared outputs' 1-5 in my story's CSS as per F2Andy's advice. If I could have my way, I'm looking for a solution that's somewhat of a "melding" of what I'm already doing and what F2Andy is doing.

Thanks!

Best Answer

  • historic66 wrote: »
    <<nobr>>
    <<set $location = "Woods [South] - Shack">>
    <<set $roomWidth = 10>>
    <<set $roomLength = 10>><</nobr>>
    
    The <<nobr>> macro converts line breaks into spaces, the <<silently>> macro suppresses output. There's no reason to generate output at all there, so the latter is what you should be using.

    historic66 wrote: »
    <<display "header">>
    
    If the header passage is supposed to be some kind of global passage header, the PassageHeader special passage exists for that very purpose.

    historic66 wrote: »
    […] The shack is <<print $roomWidth>> feet by <<print $roomLength>> feet. […]
    
    I don't know if you're aware, however, you do not have to use the <<print>> macro simply to print story/temporary variables. The naked variable markup allows that to be written as the following:
    […] The shack is $roomWidth feet by $roomLength feet. […]
    


    historic66 wrote: »
    […] <span id="shovel"><<click "shovel">></span><<replace "#shovel">>shovel<</replace>><<replace "#output1">>You pick up the shovel and put it in your backpack.<</replace>><</click>> […]
    
    […] <span id="lamp"><<click "lamp">></span><<replace "#lamp">><span id="keyItem">lamp</span><</replace>><<replace "#output1">>You pick up the <span id="keyItem">lamp</span> and put it in your backpack.<</replace>><</click>> […]
    
    <span id="output1"></span>
    
    In both of the above cases, you have the opening <span> tag outside of the <<click>> and its closing tag inside the <<click>>, that's never going to work. You cannot interleave the tags of non-void/container pieces of markup like that. Also, the <<click>> macro is deprecated, the <<link>> macro is its replacement.

    Using <<link>> and placing the <span> tags correctly would look like the following:
    <span id="shovel"><<link "shovel">><<replace "#shovel">>shovel<</replace>><<replace "#output1">>You pick up the shovel and put it in your backpack.<</replace>><</link>></span>
    
    <span id="lamp"><<link "lamp">><<replace "#lamp">><span id="keyItem">lamp</span><</replace>><<replace "#output1">>You pick up the <span id="keyItem">lamp</span> and put it in your backpack.<</replace>><</link>></span>
    


    That said, and while you could do it the way you're attempting—as I just showed—if you want the links to be single use, then it would be simpler to start with the <<linkreplace>> macro. For example:
    <<linkreplace "shovel">>shovel<<replace "#output1">>You pick up the shovel and put it in your backpack.<</replace>><</linkreplace>>
    
    <<linkreplace "lamp">><span id="keyItem">lamp</span><<replace "#output1">>You pick up the <span id="keyItem">lamp</span> and put it in your backpack.<</replace>><</linkreplace>>
    

Answers

Sign In or Register to comment.