4ian / GDevelop

🎮 Open-source, cross-platform 2D/3D/multiplayer game engine designed for everyone.
https://gdevelop.io
Other
10.83k stars 849 forks source link

Dialogue Tree Extension: DialogueTree::Variable only returns the correct value if dialogue is running #3097

Closed MechanicalPen closed 3 years ago

MechanicalPen commented 3 years ago

The bug

When using the Dialogue Tree extension's expression DialogueTree::Variable("someVariableName"), the expression gives a value of 0 unless the condition Dialogue is running would return true. This makes it difficult to use dialogue variables to control game state.

To Reproduce

Steps to reproduce the behavior:

  1. use Dialogue Tree to run dialogue
  2. have that dialogue branch set a Yarn variable
  3. end the dialogue (Dialogue is no longer running)
  4. attempt to use that variable in an expression
  5. See that the expression gives 0

Other details

blurymind commented 3 years ago

Yes unfortunately the action sets it directly to the running instance of bondagejs. This is what is used by the parser to evaluate the dialogue flow unfortunately. You do however have actions to get it and set it, so in theory should be able to store it to a variable before stopping it and restore it from the same variable too.

One simple fix for this would be to make gdevelop keep the state while the game is running and set it to yarn.

There is also the fact that the instance of bondagejs doesn't really get destroyed between dialogue interactions. If that happened, the demo game wouldn't really work as expected.

I am not sure why you are manually stopping it. To be fair I haven't looked at the dialogue tree extension for some time now. Maybe I should revisit it again soon

On Sun, 26 Sep 2021, 18:26 MechanicalPen, @.***> wrote:

The bug

When using the Dialogue Tree extension's expression DialogueTree::Variable("someVariableName"), the expression gives a value of 0 unless the condition Dialogue is running would return true. This makes it difficult to use dialogue variables to control game state. To Reproduce

Steps to reproduce the behavior:

  1. use Dialogue Tree to run dialogue
  2. have that dialogue branch set a Yarn variable
  3. end the dialogue (Dialogue is no longer running)
  4. attempt to use that variable in an expression
  5. See that the expression gives 0

Other details

  • The Set dialogue state variable action does not work this way; dialogue variables can be set at any time during the game. At the very least setting a dialogue variable and getting a dialogue variable should behave consistently.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/4ian/GDevelop/issues/3097, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRRWVI3QFWKNSBZBQMQ4L3UD43TVANCNFSM5EY4XLFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

MechanicalPen commented 3 years ago

The expression DialogueTree::Variable uses gdjs.dialogueTree.getVariable to do its job. gdjs.dialogueTree.getVariable checks this.dialogueIsRunning and if dialogue isn't running, returns ''. Simply replacing this.dialogueIsRunning with this.runner && this.runner.variables fixes this issue for me so that's what I ended up doing.

I am not manually stopping dialogue at any point; dialogue finishes and then in some other game scene (not in dialogue) I want to use "Compare dialogue state boolean variable" to show or hide a sprite. Using dialogue variables for game state as well as dialogue is very convenient.

blurymind commented 3 years ago

I guess it makes sense. Would you mind making a pr with your change? I will help review it if it helps.

On Mon, 27 Sep 2021, 18:53 MechanicalPen, @.***> wrote:

The expression DialogueTree::Variable uses gdjs.dialogueTree.getVariable to do its job. gdjs.dialogueTree.getVariable checks this.dialogueIsRunning and if dialogue isn't running, returns ''. Simply replacing this.dialogueIsRunning with this.runner && this.runner.variables fixes this issue for me so that's what I ended up doing.

I am not manually stopping dialogue at any point; dialogue finishes and then in some other game scene (not in dialogue) I want to use "Compare dialogue state boolean variable" to show or hide a sprite. Using dialogue variables for game state as well as dialogue is very convenient.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/4ian/GDevelop/issues/3097#issuecomment-928005681, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRRWVJXD3Q3RM345CHRE4LUECHOFANCNFSM5EY4XLFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

MechanicalPen commented 3 years ago

I actually just monkey patched the method in my game as I'm in the middle of a game jam. I'll attempt to submit a PR over the weekend.

MechanicalPen commented 3 years ago

https://github.com/4ian/GDevelop/pull/3127

4ian commented 3 years ago

The fix looks good, thanks for submitting this! 👍 Closing this issue now that this is solved.