More fun
Want to support CHYOA?
Disable your Ad Blocker! Thanks :)

Chapter 3 by gene.sis gene.sis

_

Conditional Branches - If-Statements

You can use If-Statements to manipulate your chapter, depending on the current score of the reader.

  1. basic syntax with "if" and "endif":
    She wears a {if Temperature <= 50}warm winter {endif}coat.

    If-Statements always begin with {if condition} and end with {endif}.
    A condition always consists of a variable name, an operator, and a value. Variable names are case sensitive.

    In the above example,
    "Temperature" is the variable name,
    "<=" is the operator and
    "50" is the value.

    If the score of Temperature is less than or equal to 50, the output will be
    She wears a warm winter coat.
    If the if statement fails, the output will be
    She wears a coat.

  2. operators and values:
    available operators:

    • equal: = or ==
    • not equal: !=
    • less than: <
    • less than or equal to: <=
    • greater than: >
    • greater than or equal to: >=

    allowed values:

    • positive values like "+10" or "15"
    • negative values like "-20"
    • boolean values "true" or "1" and "false" or "0"
  3. additional statement "elseif":
    She wears {if Temperature <= 50}a warm winter coat and {elseif Temperature <= 70}blue jeans, a sweater, and {endif}high heels.

    You can use additional "elseif" statements to check for more conditions with different output.

    If the score of Temperature is less than or equal to 50, the output will be
    She wears a warm winter coat and high heels.
    If the if statement fails and the score of Temperature is less than or equal 70, the output will be
    She wears blue jeans, a sweater, and high heels.
    If the if and elseif statements fail, the output will be
    She wears high heels.

  4. additional statement "else":
    She wears {if Temperature <= 50}a warm winter coat and{else}blue jeans, a sweater, and{endif} high heels.

    An "else" statement can be used for a default text if all previous statements fail. It is only possible to use one "else" statement and it has to be the last statement before "endif".

    If the score of Temperature is less than or equal to 50, the output will be
    She wears a warm winter coat and high heels.
    If the if statement fails, the output will be
    She wears blue jeans, a sweater, and high heels.

  5. complex syntax:
    She wears {if Temperature <= 50}a warm winter coat and {elseif Temperature <= 70}blue jeans, a sweater, and {elseif Temperature <= 80}blue jeans, a shirt, and {elseif Temperature <= 85}a summer dress and {elseif Exhibitionism <= 50}a bikini and {elseif Exhibitionism <= 80}a bikini bottom and {else}nothing but {endif}high heels.

    You can use as many "elseif" statements as you need. You can use different score variables for comparison in every statement.

    If the score of Temperature is less than or equal to 50, the output will be
    She wears a warm winter coat and high heels.
    If the if statement fails and the score of Temperature is less than or equal to 70, the output will be
    She wears blue jeans, a sweater, and high heels.
    If the if and elseif statements fail and the score of Temperature is less than or equal to 80, the output will be
    She wears blue jeans, a shirt, and high heels.
    If the if and elseif statements fail and the score of Temperature is less than or equal to 85, the output will be
    She wears a summer dress and high heels.
    If the if and elseif statements fail and the score of Exhibitionism is less than or equal to 50, the output will be
    She wears a bikini and high heels.
    If the if and elseif statements fail and the score of Exhibitionism is less than or equal to 80, the output will be
    She wears a bikini bottom and high heels.
    If the if and elseif statements fail, the output will be
    She wears nothing but high heels.

  6. nesting:
    She wears {if Temperature <= 50}a warm {if favorite Color = 1}brown {endif}winter coat and {else}blue jeans, a {if favorite Color = 2}blue {else}white {endif}sweater, and {endif}high heels.

    You can nest if statements

    If the score of Temperature is less than or equal to 50 and the score of favorite Color is 1, the output will be
    She wears a warm brown winter coat and high heels.
    If the score of Temperature is less than or equal to 50 and the second if statement fails, the output will be
    She wears a warm winter coat and high heels.
    If the first if statement fails and the score of favorite Color is 2, the output will be
    She wears blue jeans, a blue sweater, and high heels.
    If the first if statement fails and the second if statement fails, the output will be
    She wears blue jeans, a white sweater, and high heels.

  7. structuring of the if-statements:
    She wears {if
                    Temperature <= 50}a warm {if
                                    favorite Color = 1}brown {endif
                            }winter coat and {else
                    }blue jeans, a {if
                                    favorite Color = 2}blue {else
                                            }white {endif
                            }sweater, and {endif
    }high heels.

    You can structure your code with line breaks before conditions and before "}". If you use unnecessary line breaks between } and { it may affect the appearance of your chapter.

  8. default text when game mode is not active:
    You can choose, which condition should be considered as true if game mode is not active. Just place an "@" directly behind "if" or "elseif". If you don't mark a condition, the else statement will be used (if available).

    She wears {if@ Temperature <= 50}a warm winter coat and {elseif Temperature <= 70}blue jeans, a sweater, and {else}blue jeans, a shirt, and {endif}high heels.
    If game mode is not active, the output will be
    She wears a warm winter coat and high heels.

    She wears {if Temperature <= 50}a warm winter coat and {elseif@ Temperature <= 70}blue jeans, a sweater, and {else}blue jeans, a shirt, and {endif}high heels.
    If game mode is not active, the output will be
    She wears blue jeans, a sweater, and high heels.

    She wears {if Temperature <= 50}a warm winter coat and {elseif Temperature <= 70}blue jeans, a sweater, and {else}blue jeans, a shirt, and {endif}high heels.
    If game mode is not active, the output will be
    She wears blue jeans, a shirt, and high heels.

    She wears {if Temperature <= 50}a warm winter coat and {elseif Temperature <= 70}blue jeans, a sweater, and {endif}high heels.
    If game mode is not active, the output will be
    She wears high heels.

  9. miscellaneous:
    • using the same variable name for different types of variables may cause problems
    • when comparing a boolean type variable with "true" or "false", the operators "<", "<=", ">" and ">=" will always return false
    • if a variable isn't present in the reader's score, the statement will fail

_

  • No further chapters
Want to support CHYOA?
Disable your Ad Blocker! Thanks :)