Embedding if statements

Discussion in 'CHYOA General' started by robyna, Apr 7, 2020.

  1. robyna

    robyna Virgin

    I haven't been able to embed if statements (or find any information about doing an 'and' in an if statement. There are times when I'd like multiple conditions to be met (e.g., affection over a certain level and a particular event having taken place). So far, when I've attempted to embed if statements (sample below) it doesn't work.

    {if Amy>50}Matt kissed Amy on the mouth {if amydance=true}and drew her into a dance posture{endif} before setting her down lightly{else}Matt smacked Amy across her butt{endif}.

    alternately

    {if Amy>50 and amydance=true}Matt kissed Amy on the mouth and drew her into a dance posture{elseif Amy>50}Matt kissed Amy on the mouth{else}Matt smacked Amy across her butt{endif}.

    Any thoughts?
     
  2. Almax

    Almax Really Experienced

    The first one's the way to go, and it looks to me like it'd work (I normally capitalise True and False but that shouldn't be a problem!). I've done stuff like that before and it's worked fine -- are the variables properly named? For example, are you writing "amydance" when it's really "AmyDance"? And then are the variables already defined in the chapter? And are you looking at the chapter in Game Mode while the variables are set as they should be? When you're not in Game Mode, the default text is always the "else" case (unless you use an @ sign! For example {if@ x = 4}, or something like that).

    If you're looking at it in Game Mode, and the variables are properly named and have the proper values, then I'm not sure! Stuff like that has always worked out for me. I hope you can get it all fixed!
     
    insertnamehere likes this.
  3. insertnamehere

    insertnamehere Really Really Experienced

    Logic gates aren't supported in CHYOA. In your writing, they can normally be achieved with nested if-statements as you've done, though more complex conditions will require a lot of copy-pasting text.

    When you say the code doesn't work, what exactly is it showing? I can't think of any mistake you've made particular to nested if-statements. Maybe put spaces and capitals as Almax has suggested, e.g. {if amydance = True}. Check your variable capitalisation. Ensure the variable actually exists before that chapter is reached, though even that shouldn't be a problem, since it'll just default to the {else} condition.
     
  4. robyna

    robyna Virgin

    Okay, thanks. I'll work on making sure my nested statements are correct. I had a couple of fails and assumed they didn't work but if they should, it was probably my problem.



     
  5. robyna

    robyna Virgin

    Thanks Almax. I will go with the nested option and double-check my variable names.


     
  6. gene.sis

    gene.sis CHYOA Guru

    One problem with the if-statements is that there is no naming convention for variables.
    So it isn't possible to decide if a parenthesis is a part of a variable name or is there to group conditions.

    I could imagine a structure like
    {if a = true}{andif b = true} shown if a and b are true{endif}
    but I think it could be difficult to work with that. (In general, implementation like that should be possible.)

    It also doesn't solve the problem of comparing variables with each other (x > y) and so I would rather rely on precalculated variables as well. (This isn't possible right now.)
     
  7. robyna

    robyna Virgin

    Thanks, gen.sis.

    Yes variable comparison would be helpful. E.g., to select which girl to date based on highest score, etc. I guess we're lucky to have the degree of conditionality we do have. Just need to figure out how best to take advantage of it.

    Rob