Howdy, Stranger!

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

Trying to make links disappear with variables

Hey!

It's my first time using variables and I've run into an issue I wonder if anyone could assist with. I hope this comes out making sense! I'm on SugarCube2.14

In the situation the player is posed a question and has five possible choices of answer. One is correct and will lead out of the "loop", and every other answer will lead to a passage with text specific to that answer, with the same choices as before minus the one they just clicked.

My attempt to do this was the following: I have two passages: startpage and startpage2.

In startpage the first link is
[[Pray?->startpage2][$pray to "true"]]

and in startpage2 I put
<<if $pray is true>>'That may be the dumbest thing I've heard all day, and trust me, I've heard a LOT of dumb sh*t today.'<</if>>

I did the same for the other resulting answers, and for the choices displayed in startpage2 I put
<<if $pray is false>>[[Pray?]]<</if>>
so that it won't display when you have already clicked it in startpage.

Anyone know if this is the right approach, or am I completely mad? I must be somewhat mad, because my version doesn't work - the startpage2 answer doesn't display.

Another issue I see with this is the empty space created by the hidden answers in startpage2.

I would really appreciate any help with this. Cheers,
Jellyfoosh

Comments

  • There are potentially three issues with your examples.

    1. [potential] Your example does not show when you are initialising the $pray variable to false, which you need to do because SugarCube's variables do not default to false.

    Defaulting $pray variable to false in your StoryInit special passage will fix this issue.
    <<set $pray to false>>
    


    2. You assign a String value of "true" to the $pray variable when the Pray? link is selected but you are checking for the Boolean value of true in the <<if>> macro. Those two values are of different data types which is why the is-exactly-the-same compassion is failing.

    Assign a Boolean value of true to when the link is selected will fix this issue,
    [[Pray?->startpage2][$pray to true]]
    


    3. The following is a more correct way to test is a variable is true or if a variable is false.
    <<set $varA to true>>
    <<set $varB to false>>
    
    <<if $varA>>The A variable equals true<</if>>
    
    
    <<if not $varB>>The B variable equals false<</if>>
    
  • Hey Greyelf, thanks for explaining.

    I switched to a boolean value like you showed and the <<if>> macro is working now. I also defaulted the variables to false in a StoryInit passage.

    The issues I'm still encountering are the following:

    1. The hidden answer texts and hidden links (after you have clicked them once) are occupying space. The only thing I've found is that you can make each section occupy only one line, either with curly brackets or by simply removing the line breaks that I have below (right now they are like that for clarity only). Any ideas how the empty space can be removed completely?

    2. Since the variable doesn't reset to the default false after you click a different link, the previous answer texts are still displayed. I'm beginning to think that doing this in just two passages simply isn't the best way of doing it. Because even if I return the condition to false to remove the answer text, the link that should be hidden will appear again.

    Here is my entire startpage2 markup:
    <<if $pray is true>>'That may be the dumbest thing I've heard all day, and trust me, I've heard a LOT of dumb sh*t today.'<</if>>
    
    <<if $snakedance is true>>The grublin stares at you with a grimace bordering on concern. 'What? No! Whatever that is boy, never do that. Never. Okay? Good.'<</if>>
    
    <<if $awesome is true>>The Grublin sighs. 'No. Try again.'<</if>>
    
    <<if $impotence is true>>'No, that's how you cure impotence. Try again.'<</if>>
    
    <<if $insult is true>>Indecision flashes across the Grublins face for the first time. 'That... You know, that's actually a good idea - but! - there's a better way.'<</if>>
    
    <<if $pray is false>>[[Pray?->startpage2][$pray to true]]<</if>>
    <<if $snakedance is false>>[[Cover yourself in mud and do the snake dance?->startpage2][$snakedance to true]]<</if>>
    [[Blood Sacrifice?]]
    <<if $awesome is false>>[[Be awesome?->startpage2][$awesome to true]]<</if>>
    <<if $impotence is false>>[[Swing a cows liver on a rope above your head at full moon?->startpage2][$impotence to true]]<</if>>
    <<if $insult is false>>[[Insult them.->startpage2][$insult to true]]<</if>>
    



  • Generally every line-break you add to the content of a Passage gets converted to a HTML br element in the output that gets displayed on the page.

    There are two techniques which can be combined to control the formatting of conditional text.

    1. Using Line Continuations to suppress the line-breaks after the <<if>> macro end tag.

    2. Adding the line-break within the <<if>> macro's body, which causes the line-break to only appear when the rest of the related text is displayed.

    The following is a modified version of your example, notice how I use backslash characters to suppress line-breaks between the <<if>> macros, and how I added line-breaks within the <<if>> macro bodies.
    note: I have also remove the is true and the is false comparisons from the <<if>> macro expressions.
    <<if $pray>>'That may be the dumbest thing I've heard all day, and trust me, I've heard a LOT of dumb sh*t today.'
    <</if>>\
    \
    <<if $snakedance>>The grublin stares at you with a grimace bordering on concern. 'What? No! Whatever that is boy, never do that. Never. Okay? Good.'
    <</if>>\
    \
    <<if $awesome>>The Grublin sighs. 'No. Try again.'
    <</if>>\
    \
    <<if $impotence>>'No, that's how you cure impotence. Try again.'
    <</if>>\
    \
    <<if $insult>>Indecision flashes across the Grublins face for the first time. 'That... You know, that's actually a good idea - but! - there's a better way.'
    <</if>>\
    \
    <<if not $pray>>[[Pray?->startpage2][$pray to true]]
    <</if>>\
    <<if not $snakedance>>[[Cover yourself in mud and do the snake dance?->startpage2][$snakedance to true]]
    <</if>>\
    [[Blood Sacrifice?]]
    <<if not $awesome>>[[Be awesome?->startpage2][$awesome to true]]
    <</if>>\
    <<if not $impotence>>[[Swing a cows liver on a rope above your head at full moon?->startpage2][$impotence to true]]
    <</if>>\
    <<if not $insult>>[[Insult them.->startpage2][$insult to true]]
    <</if>>
    
  • Thanks a lot for the tips!

    I ended up making a separate passage for each answer, to avoid the answers piling on top of each other instead of correctly appearing alone at the top after you click a link.

    I also used your tip with the backslash to avoid the links themselves leaving gaps when they have been clicked and then therefore hidden.

    Everything is working perfectly now, thanks so much! :)
Sign In or Register to comment.