A couple questions about if statements

Discussion in 'CHYOA General' started by RinTezukasLittleGoldfishCracker, Feb 13, 2024.

  1. Hello all, I apologize if this isn't the correct place for posting this.

    Basically, I'm wondering if there's a way I could include multiple variables in a single if Statement? For example, could I include a character's disposition {if CharacterDisposition > 0} AND whether or not that character is alive {CharacterLife = true}?

    This would be especially helpful when getting two characters to talk to each other, because I have to make sure that both characters are actually alive; {if AlistairLife = true}{if MorriganLife = true}This dialogue appears only when both characters are alive.{endif}

    Is this possible? I'd be grateful if someone could help me find a possible workaround if this isn't a thing.

    Also, I'm fairly certain there isn't, but is there a way to completely remove a variable? I know you can hide them, but it would be nice if there's a way to not have to load 50 variables I'm not using just because I needed them for one chapter.
     
    Last edited: Feb 14, 2024
  2. gene.sis

    gene.sis CHYOA Guru

    In general, that is possible.
    You have basically the right syntax already.
    Code:
    {if AlistairLife = true}{if MorriganLife = true}Dialog{endif}{endif}
    If either of the variables is false, the statements won't reach the dialog part in the inner statement.

    In this case, you can also do something like
    Code:
    {if AlistairLife = true}{if MorriganLife = true}Dialog{elseif}Monolog Alistair{endif}{elseif MorriganLife = true}Monolog Morrigan{else}Silence{endif}
    There should be cases where this won't work.
    E.g. if you have 2 levers. If either of them is pulled, the door is open. Are both or neither of them pulled, the door is closed.
    Code:
    {if Pulled A = true}{if Pulled B = true}Closed{elseif}Open{endif}{elseif Pulled B = true}Open{else}Closed{endif}
    Here, the problem is, that the text for both "Closed" and "Open" appears twice. So you would need to copy the text and adjust both parts whenever there is a change.
    This might not be a problem with a short text but could be problematic when you have bigger structures within the clauses.
    (This might even be a bigger problem when you have more variables.)

    One workaround in this situation might be to have a third variable with a starting value of 0. If you
    - pull lever A -> Counter +1
    - push lever A -> Counter -1
    - pull lever B -> Counter -1
    - push lever B -> Counter +1
    So if both levers are pulled, the value of Counter will be 0.
    If only A is pulled, it is +1 and if only B is pulled, it is -1.
    Then, you can use
    Code:
    {if Counter = 0}Closed{else}Open{endif}

    Another way to solve some issues would be to use linking chapters and combine the conditions.
    So you could use 4 chapters that lead to a 5th chapter that can't be accessed.
    Conditions / Score Change
    - AlistairLife = true AND MorriganLife = true / Content = 1
    - AlistairLife = true AND MorriganLife = false / Content = 2
    - AlistairLife = false AND MorriganLife = true / Content = 3
    - AlistairLife = false AND MorriganLife = false / Content = 4
    and then use the syntax
    Code:
    {if Content = 1}Dialog{elseif Content = 2}Monolog Alistair{elseif Content = 3}Monolog Morrigan{else}Silence{endif}
    in the destination chapter.

    The more variables and possible values you need to check, the less feasible it is.


    Currently, there is no way to remove a variable from the Reader's Score.
    A workaround would be to reuse variables, though it might not be as easy to identify them if you use generic variable names and you need to be careful to set them to the intended value when switching to another scene.
    50 variables don't seem to be a problem.
     
  3. Thank you, that's very helpful. I figured it would be something simple I just wasn't seeing.