hylyh / bondage.js

Javascript-based parser for the Yarn dialogue tree markup language
https://www.npmjs.com/package/bondage
MIT License
57 stars 21 forks source link

Bug accessing the data in a node #45

Closed justjuank closed 5 years ago

justjuank commented 5 years ago

Hello, I believe there is a bug in the data of a node. I'm getting data: undefined under the following circumnstances:

-I have node A, B, and C -Node A doesn't has any text, just an <<if>> statement that makes it go to B -Node B doesn't has any text, just an <<if>> statement that makes it go to C -Node C has several lines of text, at this point data is undefined and I'm unable to access the title of the current node for example.

If I add text to Node A the data property is correctly populated for that node, but Node C continues with data undefined.

Can anyone confirm this is a bug?

hylyh commented 5 years ago

Hi! Would you be able to give me some exact yarn node text to minimally replicate this?

justjuank commented 5 years ago

Hi, thanks for replying back, ok so here's a reproducible example (I don't know if this is what you need):

NodeA:

<<if 1==1>>
<<doSomething>>
[[NodeB]]
<<endif>>

NodeB:

<<if 1==1>>
<<doSomething>>
[[NodeC]]
<<endif>>

NodeC:

Some regular text
Another regular text

I want to check the .data when I call <<doSomething>> to check what's the .title of the current node.

If I print the value to the console this is what I get:

CommandResult {text: "doSomething", data: undefined}
data: undefined
text: "doSomething"

So maybe the CommandResult is not getting the data property set correctly. Maybe it is intended? If so any work arounds?

Thanks

hylyh commented 5 years ago

This does look like a bug! I'm looking into it. A sorta cruddy temporary workaround might be to have some special text line that you immediately skip over before the conditional that you can use to grab the data for the node before the command is called. Not very graceful though :/

hylyh commented 5 years ago

Good news! The fix was easier than I expected. Will get merged and pushed up to npm as soon as the ci finishes

hylyh commented 5 years ago

Pushed! Apologies for the delays in getting back to you. Let me know if you have any other issues!

justjuank commented 5 years ago

Awesome! it works perfectly, thank you very much!