Ifs and Elseifs and Elses

The error I’m getting is: “invalid indent, expected at least one line in 'if true block.”

My code looks like this:

*if ((deathcount = 2) and not (jura)) and not (sham)
  You lost Jura and Shamora.

Help?

What happens if you add an extra pair of parentheses to your code to ensure CS must evaluate every condition of the *if statement? Like this:

*if (((deathcount = 2) and not (jura)) and not (sham))
  You lost Jura and Shamora.

Alternatively, what happens if you maintain the current structure but replace not (variable) with (variable = false)? For example:

*if ((deathcount = 2) and (jura = false)) and (sham = false)
  You lost Jura and Shamora.

I’ve got a weird feeling that ChoiceScript is arbitrarily assuming the *if line ends somewhere before it actually does, and is treating the additional conditions as non-indented following lines. Do either of the above resolve the issue?

2 Likes

Neither works… Although I think I know what I did wrong. It should be *elseif, not *if. I’ll try that and see if that fixes it.

Thank you.

Edit: Nope. No idea what’s bugging this.

Best guess: The problem likely isn’t actually this line, in the most literal sense. The problem is likely either another line, or the interaction between this line and another line. What do the surrounding lines look like? Or, well, the functional bits of the surrounding lines. It’s unlikely narration or dialog will contribute to the problem.

Don’t ask me why (at this point, everything kind of looks the same, but I think it was another before this one *if I forgot to write as *elseif) but now I’ve got the same issue 100 lines forward. This is how the code looks like:

*else
  All of your companions are by your side
  *if turn1 = 1
    *set turnname "Wolf"
    *goto string
  *elseif turn1 = 2
    *set turnname "Jura"
    *goto string

And so on. Any ideas? :sweat:

When you use not in an *if with multiple options, you have to format it like this:

*if ((deathcount = 2) and (not(jura))) and (not(sham))
    ...

Not sure what the issue is with your other snippet.

2 Likes

Alright, it seems like the first issue is fixed, but I feel bad creating another thread for this, so I might as well ask here:

This is my code
*elseif (deathcount = 3) 
  You lost everyone. 
*else
  *goto all
*label all
*if (deathcount = 0)
  All of your companions are by your side.

(regarding the *else command) “It is illegal to fall in to an else statement, you must goto…”

I’m not sure what I’m doing wrong, sorry for inconveniencing

If you aren’t using implicit control flow, then when you add an *else and/or *elseif to a block of *if statements, you also need a *goto for every statement in the block. Not just the *else, but also every *elseif and *if in the block.

3 Likes

the problem in your code is not the else part, its the elseif ones.

you cant just show text only, it has to go somewhere ( *goto / *finish / others )

2 Likes

I am an idiot (in the best of senses) and finally figured out why the frick this didn’t work. I basically cut off an *if I had started just before the (not and not) *if; But hadn’t realised until I went to sleep, woke up, drank a cup of tea and sat down in front of my pc again.

Thanks for the help, everyone, tho :sweat_smile:

3 Likes

Question resolved!