Howdy, Stranger!

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

Empty spaces where code is in Sugarcube?

I'm having a bit of a problem with how sometimes with code I'll have a large spat of empty space, just from the number of options available.

For instance, let's say I let the player decide what the value of $variable is.

Hello there.

<<if $variable = 1>>
Show this sentence
<<endif>>

<<if $variable = 2>>
Show this sentence
<<endif>>

<<if $variable = 3>>
Show this sentence
<<endif>>

Now, if the player chooses 3, they're going to have a long blank space where the code for 1 and 2 is. The code there will not be visible because the player chose 3, but even though it's "hidden from view", the space it takes up is still there and makes it rather unappealing. The passage would basically look like this from the players POV.

Hello there.










Show this sentence

Whereas I'd rather it look something more like this.

Hello there.

Show this sentence

Is there a way to make this possible? Any help is greatly appreciated.

Comments

  • And I also need to say that sometimes it will be for various variables that are already active.

    for instance

    You have <<print $people>> doing <<print $task>>
    You have <<print $people>> doing <<print $task2>>
    You have <<print $people>> doing <<print $task3>>

    But task2 and task3 are not yet available in the game, so I don't think they should be visible, even as "0 peole doing task2".

    So it would be more like

    <<if $task2Available = 1>> You have <<print $people>> doing <<print $task2>><<endif>>

    Which would have to be invisible, and again, would be a long black empty space. Especially if its on a stat menu, it'd be very obvious how much stuff is not being shown but exists because of the large black space.

    The <<nobr>> command will not work because then everything would be just on one line, and that's also not what I want.

  • First. You're using the assignment operator (=) where you should be using an equality operator (eq, is, ==, ===).

    If only one out of a set of conditions may be true, then you could simply do something like this:
    Preceding sentence.
    <<if $variable is 1>>
    Show only this sentence.
    <<elseif $variable is 2>>
    Or show only this sentence.
    <<elseif $variable is 3>>
    Or show only this sentence.
    <</if>>
    Following sentence.
    

    If multiple conditions may be true, then you could do something like this (using line continuations):
    Preceding sentence.
    <<if $variable is 1>>
    Show this sentence.
    <</if>>\
    <<if $variable is 2>>
    Show this sentence.
    <</if>>\
    <<if $variable is 3>>
    Show this sentence.
    <</if>>
    Following sentence.
    

    The setup for the tasks listing would be similar (again, using line continuations):
    Preceding sentence.
    
    <<if $task1Available>>\
    You have $people doing $task1.
    <</if>>\
    <<if $task2Available>>\
    You have $people doing $task2.
    <</if>>\
    <<if $task3Available>>\
    You have $people doing $task3.
    <</if>>
    Following sentence.
    
  • First. You're using the assignment operator (=) where you should be using an equality operator (eq, is, ==, ===).

    If only one out of a set of conditions may be true, then you could simply do something like this:
    Preceding sentence.
    <<if $variable is 1>>
    Show only this sentence.
    <<elseif $variable is 2>>
    Or show only this sentence.
    <<elseif $variable is 3>>
    Or show only this sentence.
    <</if>>
    Following sentence.
    

    If multiple conditions may be true, then you could do something like this (using line continuations):
    Preceding sentence.
    <<if $variable is 1>>
    Show this sentence.
    <</if>>\
    <<if $variable is 2>>
    Show this sentence.
    <</if>>\
    <<if $variable is 3>>
    Show this sentence.
    <</if>>
    Following sentence.
    

    The setup for the tasks listing would be similar (again, using line continuations):
    Preceding sentence.
    
    <<if $task1Available>>\
    You have $people doing $task1.
    <</if>>\
    <<if $task2Available>>\
    You have $people doing $task2.
    <</if>>\
    <<if $task3Available>>\
    You have $people doing $task3.
    <</if>>
    Following sentence.
    

    I noticed for the last example, $task1Available and the others weren't assigned a value. Could you explain how I'd execute this (what value $task1-3Available would have to be to register a true or false), and the syntax behind the line continuations?
  • They're not assigned a value because it's a conditional expression. You test values in conditional expressions you don't assign them (technically you can, but don't; also, by default, SugarCube will yell at you if you try).

    What you meant to say was that I wasn't testing the $variables against a value. As to why, I didn't include a value because I assumed you were using them as booleans (i.e. true/false, on/off, yes/no). If that's not the case, then you can simply use the conditional expressions you were using before.

    As to what you'd assign to them to be able to use them that way, you'd probably want to use the true and false boolean literals. For example:
    <<set
    	$task1Available to true,  /* Available. */
    	$task2Available to false, /* Unavailable. */
    	$task3Available to true   /* Available. */
    >>
    

    TL;DR: If you're using $variables as booleans, then use real boolean values and simply use the $variables as-is in conditional expressions.
  • They're not assigned a value because it's a conditional expression. You test values in conditional expressions you don't assign them (technically you can, but don't; also, by default, SugarCube will yell at you if you try).

    What you meant to say was that I wasn't testing the $variables against a value. As to why, I didn't include a value because I assumed you were using them as booleans (i.e. true/false, on/off, yes/no). If that's not the case, then you can simply use the conditional expressions you were using before.

    As to what you'd assign to them to be able to use them that way, you'd probably want to use the true and false boolean literals. For example:
    <<set
    	$task1Available to true,  /* Available. */
    	$task2Available to false, /* Unavailable. */
    	$task3Available to true   /* Available. */
    >>
    

    TL;DR: If you're using $variables as booleans, then use real boolean values and simply use the $variables as-is in conditional expressions.

    I was able to set this feature up in the right respect within my story, and got it to work exactly how I imagined it to be. I've also inadvertently learned far more efficient means for code syntax from your examples, such as you can set more than one variable within the same bracket.

    Thank you very much!
Sign In or Register to comment.