ephread / inkgd

Implementation of inkle's Ink in pure GDScript for Godot, with editor support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

else statement in switch block doesnt redirect if switch statement is 1

2shady4u opened this issue · comments

Describe the bug
I'm not really sure if this is an inkgd or a ink-issue in general, but when there's a switch statement such as this:

=== knot ===
{some_variable:
    - else: -> else_divert
}

= else_divert
It is else!
-> DONE

The switch will only choose the 'else' divert if the some_variable is equal to zero, otherwise it just gets stuck.
This is unexpected behavior as I would expect that the else-clause serves as a "catch-all" sort of thing in a switch
statement. In other words: 'If nothing applies, choose the else divert'

To Reproduce
I made a repository that replicates the issue here.
In that Godot project you have a player (controlled with the ARROW keys) that can talk to either a red or a green NPC.
You talk to them by overlapping with them and pressing the SPACEBAR or ENTER key.

Capture

Their dialogue will appear in the console and talking to the green NPC works flawlessly!

elsewithgreen

But when talking to the red NPC, all dialogues will be empty after that.... and the switch statement never diverts...

elsewithred

Like you can see in the image above, the dialogue with the red NPC appears and then.... nothing...
Even when talking to the green NPC, you just get an empty line back from the story.

Expected behavior
I would expect the 'else' clause to serve as a way to capture everything that isn't matched by any of the other clauses.
And ,as is the case here, there are no other clauses so the 'else' clause should always be chosen.

Ink files
Here's the ink-file I used for both red and green NPCs:

VAR some_variable = 1

=== green ===
It's the GREEN that I need!
{some_variable:
    - 0: -> zero
    - else: -> else_divert
}

= zero
It is zero!
-> DONE

= else_divert
It is else!
-> DONE

=== red ===
REDRUM
{some_variable:
    - else: -> else_divert
}

= else_divert
It is else!
-> DONE

Environment:

  • OS: Windows 10
  • Godot version: 3.2.2 (GDScript)

Just did a little test in Quill:

image

The switch-statement correctly diverts to the 'else_divert' in that case. So it probably is an issue with inkgd 🤔

Thanks for the detailed report @2shady4u, it's much, much appreciated and will make things easier to debug. I'll have a look this weekend!

@2shady4u so there's actually a runtime error occurring, which is why the story doesn't recover. I don't really know why it's not visible with Quill, but inky and inklecate both report it.

Screen Shot 2020-09-12 at 15 46 42

inkgd reports the issue it as well, but it's not pushed to the editor, so you have to manually look for errors in the story to see it. The next version of ink will revamp error handling but in the meantime, I'll make sure errors are pushed to the editor in debug.

I don't know if it's an ink bug or a normal behavior, it's probably a good idea to ask the folks on Discord or on the main repo. It sounds like the compiler should prevent running into this issue at runtime.

😕 okay...
It's a bit annoying that Ink doesn't catch this on compile-time...
And it's also extremely annoying that Quill doesn't crash at all! 🤣

It would indeed be easier if a hard crash would be printed to console 🤔

I'll check with the guys on the Ink discord what the issue is here, because this behavior is
just unexpected/weird/unconventional.
Like I mentioned before I would expect the "else"-statement to work exactly like "_:" in a Godot match statement.

Thanks for checking this out though 😃

I made an issue on the Quill repo as well to hopefully figure out this inconsistency.
MattConrad/Quill#14