A question about variables

Discussion in 'Authors' Hangout' started by Xenolan, Apr 13, 2025.

  1. Xenolan

    Xenolan Really Experienced

    Fellow Authors!

    I have an issue with variables in my story, It's Good to Be the King. I have a chapter which will show different text depending on what choices have been made so far, using boolean variables. Here's a simple example to demonstrate:

    Let's say that early in the story, there is the opportunity for the player to select either a sandwich or a pizza to eat. The variable is called "sandwich" and it is set to False in the chapter which presents the choice; then, depending on the choice made, it is set again to either True of False. The two options then combine back to a single branch where the story continues for a while.

    Later, there is a part where the story does this:

    Code:
    {if sandwich = 1}The sandwich isn't sitting well in your stomach!{endif}{if sandwich = 0}The pizza isn't sitting well in your stomach!{endif}
    This comes out fine if one is playing Game Mode; the text will either come up as "The sandwich isn't sitting well in your stomach!" or "The pizza isn't sitting well in your stomach!" depending on the choice made earlier and how it set the variables. However, if Game Mode is NOT engaged, I find that it will say, "The isn't sitting well in your stomach!"

    Is there any way to have the text default to something neutral? Can I code it so that it says, "Your stomach is suddenly uneasy!" in place of either of the two lines above if Game Mode is not engaged?
     
  2. gene.sis

    gene.sis CHYOA Guru

    In your example, you could do
    Code:
    {if sandwich = 1}The sandwich isn't sitting well in your stomach!{elseif sandwich = 0}The pizza isn't sitting well in your stomach!{else}"Your stomach is suddenly uneasy!"{endif}
    or (just to provide the concept of using @ to determine what should be shown when game mode is off)
    Code:
    {if@ nothing = 0}"Your stomach is suddenly uneasy!"{elseif sandwich = 1}The sandwich isn't sitting well in your stomach!{elseif sandwich = 0}The pizza isn't sitting well in your stomach!{endif}
     
    vyksin and Xenolan like this.