I am having trouble with *if commands

Hello everyone, I’ve got a bit of a head scratcher here… I cannot figure out what the problem is, and I’m hoping someone here can help me!

The Context:
I’m using choicescript IDE (and I’m pretty new to choicescript in general).

So on a secondary stat page that I creating using the *choice command, I’m trying to show the appearance of a couple npc’s, but the npc’s are gender customizable so I’m using *if commands to distinguish between a masculine appearance vs. feminine so that it will change the description that will appear on the stat page depending on the gender the player selects for either npc.

Here’s the layout of the code before I get to the problem…

*choice
     #Character Appearances (this gets you to the secondary stat page)
          *if npc1_appearance_set
               *if npc1_male = true
                    He blah blah blah
                    *finish
               *else
                    She blah blah blah
                    *finish
          *if npc2_appearance_set
               *if npc2_male = true
                    He blah blah blah
                    *finish
               *else
                    She blah blah blah
                    *finish

The Problem:
When I’m test running the game, if I choose the option that npc1 is male, then it will show npc1’s info perfectly but not the information for npc2, no matter their gender. If I choose female for npc1, both of npc2’s genders will show up as I’d like them to. This leads me to believe that it’s only when npc1_male = true that npc2 doesn’t show up, but I don’t know how to fix this. Also, if I flip them so the code for npc2 shows up before npc1, the same thing happens. If I choose the male option for npc2 then the stat page won’t display info for npc1.

Alternatively, if no one can figure out how to fix it, is there another way I can code this to get the information across? At this point there are only two major npc’s in the story, but there’s going to be more, and I want to include a physical description of all of them on that stat page, so if anyone has pointers on the easiest way to do this, I’m all ears (I’m sure it would be ten times easier if I didn’t make npc genders customizable, but gender-locking them is a short term solution and doesn’t really teach me what I’m doing wrong code wise.)

When you post code, you need to make sure we can see your indentations. Use the button that looks like </> just above where you are typing. Without seeing the indentations it is hard to see if it is an identation error that is causing your woes.

1 Like

That’s because you’re using the *finish command.

Edit: This should work:

Sounds like there’s something wrong in your indentation.

Please confirm if your indentation looks like this or not; I need to know exactly what’s wrong before moving on:

*choice
   #Character Appearances
      *if npc1_appearance_set
         *if npc1_male = true
            He blablah
            *finish
         *else
            She blablah
            *finish
      *if npc2_appearance_set
         *if npc2_male = true
            He blablah
            *finish
         *else
            She blablah
            *finish
1 Like

I updated the first post with preformatted text. Just as a reminder, you can use the </> symbol to wrap your code in reformatted text, which lets us see indentation. :slight_smile:

Ah, sorry guys, I’ve never posted on the forum before so I didn’t realize there was a special button to show indentation; thanks for making me aware!

@Szaal Yes that’s exactly what my indentation looks like and it was still happening. I wondered if it was an indentation problem so I fiddled with it, to no avail. Fortunately, the solution that @Sofia_D gave fixed the problem!
But I still don’t fully understand what I did wrong. Is the *finish command causing the game to jump to the next scene thereby skipping everything that follows npc1 in the same indentation? So if I had a npc3, I’d have to use *goto for both npc1 and npc2? In other words, no matter how many npc descriptions I include, only the last one listed in the code can use *finish instead of *goto?

1 Like

*finish means “this entire scene is over, now go to the next scene.” So yes, you’ll need *gotos.

And your last description may also not necessarily need a *finish; you can *goto that to somewhere else. Often a single chapter of many many words will only have a single *finish in it.

2 Likes

One good way to troubleshoot these problems is to read your code like a computer would: as literally and exhaustively as possible.

So when you’re reading this one, you go down to an option, and you hit the *finish command. If you were a computer, where does this command take you? What’s the next thing you look at?

Well, since it’s the *finish command, the computer skips all the way to the end of the scene!

There’s your problem.

Tell the computer to go where you want it to go.