Help me understand "illegal to fall in to *else statement" error

I can see a way to bypass this error, but the design seems unintuitive… and inconsistent. Because code doesn’t work that way, this means there must be a failure of my understanding.

The error I’m getting is line 28 of startup: It is illegal to fall in to *else statement; you must *goto or *finish before the end of the indented block.

Code demonstration below. The goodCalc function uses what appears to be a superfluous *goto/*label to evade the error, badCalc does not, longCalc has a thing that determines whether to check

*title Testbed
*author Admin

*create testInt 10
*create testBool true

It is apparent that testInt is
*gosub badCalc
.

It is apparent that testInt is
*gosub goodCalc
.

It is apparent that testInt is
*gosub longCalc

Test complete.

*finish

In the same file, below, but broken apart in the post for visibility:

*comment Functions section

*label badCalc
*if testInt >= 10
	>=10
*else
	<= 9
*return

*label goodCalc
*if testInt >= 10
	>= 10
	*goto BUTWHY
*else
	<= 9
	*goto BUTWHY
*label BUTWHY
*return

*label longCalc
It is apparent that testInt is
*if testBool
	*if testInt >= 10
		>= 10
	*elseif testInt >= 6
		>= 6
	*elseif testInt >= 4
		>= 4
	*elseif testInt >= 2
		>= 2
	*elseif testInt >= 1
		= 1
	*else
		<= 0
*else
	not selected yet.
*return

Further testing yielded another functional one:

*label returnCalc
*if testInt >= 10
	>= 10
	*return
*else
	<= 9
	*return

However, this does me no good if I want to run the *if in-line rather than as a function…

(Oh cool I won’t be so awful at formatting my posts anymore, I found the thing to increase the size of the input box.)

You can use “*set_implicit_control flow true” at the top of your file or beginning of your game, see: New ChoiceScript features: implicit control flow, gosub parameters for more info.

2 Likes

:thinking:

Well, that does fix it. Thanks!

Though, I don’t feel like I’m any closer to understanding why if/elseif/else would be so, well, janky without it.

But just to clarify, indeed badCalc won’t work properly (which is where the error should be located at).

The thing is old CScript works like that (you must put *goto or *finish on every *if no matter how or why).

But the new CScript fixed that with the *implicit_control_flow true variable. Detailed info is available at that link provided by @CJW

1 Like

As dfabulich explains in the linked thread, implicitly ‘falling’ out of a series of *ifs leaves you open to control flow bugs. In other words, it becomes vey easy to miss uncaught edge cases. Forcing you to *goto useless labels is very frustrating but it does force you to think about what you’re doing.

2 Likes

It just seems a bit strange to me that the if/elseif/else statements wouldn’t function as a self-contained unit, instead needing a dedicated escape, especially given that if you use a solo if-then, it creates a conditional insertion before continuing.

(For anyone finding this thread in the future through Google, don’t forget to *create implicit_control_flow true before you attempt to set it, natch)

1 Like

ChoiceScript makes heavy use of gotos and labels, which is uncommon in most modern high level languages. It’s expected that most people will want to change the text based on an if, and different gotos are a tidier way to achieve this. At the end of the day though, this is just how it is and it isn’t likely to change.

2 Likes