chad-ld / articy-webpreview

Articy Final Draft Web Preview Code
GNU General Public License v3.0
6 stars 0 forks source link

Conditionals / instructions don't work #1

Open SavedByZero opened 10 months ago

SavedByZero commented 10 months ago

Describe the bug Either instructions don't seem to set, or conditions don't seem to accurately process the global variables

To Reproduce Steps to reproduce the behavior: 1.Add a global variable of your choice

  1. Set the global integer variable to a value inside your dialogue flow
  2. Make one branch of dialogue based on one value of that variable, and another branch based on a different value
  3. Export as json, following the readme instructions, and make sure everything is included (including global variables)
  4. View on web server

Expected behavior Branches get chosen based on the value.

Actual behavior I set the variable (integer) to 4, but the path always gets chosen as if it's at the default value.

Desktop (please complete the following information):

SavedByZero commented 10 months ago

If this helps, my inspector showed this going on with the variable I was using (GameState.personalMemories). It looks like it's taking the result of the comparison, then saving that result over the original variable value:

processing... GameState.personalMemories= 4 [index-494a6fb0.js:13239:17](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
14:55:40.214 variables updated 
Window https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/
​
GameState: Object { personalMemories: true }
chad-ld commented 10 months ago

Thanks for submitting this! I'll try to get some time and see if I can reproduce this on my end in the coming week or so. What version of Articy were you using to export the json out of curiosity?

SavedByZero commented 10 months ago

NP. I was using draft 3 (I know the export is broken with draft X, somewhat literally)

chad-ld commented 10 months ago

I haven't used draft X yet, has that been confirmed by them it's borked? ( I understand it doesn't apply to this case, but just curious).

SavedByZero commented 10 months ago

Yeah, it's been doing this weird thing for a number of us --instead of making a file called "ProjectName.json", it makes a folder called ProjectName.json and spits out a bunch of piecemeal json files into that folder, all of which contain different parts of what normally all goes inside the single json file in draft 3. (I only know this because I'm a former programmer and know my way around json and inspectors....heh)

chad-ld commented 10 months ago

Hi @SavedByZero ! See attached flow. Is this the flow you are trying to describe above? Just wanted to make sure before I exported to the web viewer to test. If not, could you screenshot a sample flow that causes the glitch to make sure i'm setting it up right? image

SavedByZero commented 10 months ago

Similar, but you may want to add a second check in after that with something like <1 (testing for a negative).  Later on I can try to recreate a simpler test case as well because I would love to get the variables working by the weekend if at all possible. I think the inspector output was the key to what was going on.Sent from my iPhoneOn Dec 29, 2023, at 2:18 AM, Chad Briggs @.***> wrote: Hi @SavedByZero ! See attached flow. Is this the flow you are trying to describe above? Just wanted to make sure before I exported to the web viewer to test. If not, could you screenshot a sample flow that causes the glitch to make sure i'm setting it up right? image.png (view on web)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

chad-ld commented 10 months ago

Yeah, i don't know if I'll be able to take a look before the weekend to get it sorted, but i'll def try and test it to see if I can reproduce the bug. The source is all on github tho, so if you (or one of your devs) got some programming chops, you can take a whack at it too.

SavedByZero commented 10 months ago

Okay, here's a simpler test case for you that repro'd the error for me: Screen shot 1: image Screen shot 2: image

Hopefully those show up. The variable is GameState.Blarg. I set it to 2 initially, check if it's under 2 twice. It isn't at first, but somehow, it is the second time. Also, in the inspector, the GameState object is setting a property Blarg to "false" at one point.

SavedByZero commented 10 months ago

And sadly, I'm not enough of a javascript sleuth to be able to hone in on it over 30k lines of code (I'm assuming the file is that index-somebignumber.js file?), but if you know the areas that handle variable setting and comparison and can point me to them, then just maybe I could get some ideas. My best guess is still that it's saving the true/false results of the setting and comparisons to the actual variable value. First instruction shows:

processing... GameState.Blarg = 2 [index-494a6fb0.js:13239:17](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:48:09.070 variables updated 
Window https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/
​
GameState: Object { personalMemories: 0, Blarg: true }

First comparison in the inspector shows:

processing... GameState.Blarg < 2 [index-494a6fb0.js:13239:17](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:48:09.078 variables updated 
Window https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/
​
GameState: Object { personalMemories: 0, Blarg: false }
​​
Blarg: false

Second comparison shows:

setting current Node Ids: 
Array [ {…} ]
​
0: Object { Type: "Condition", Properties: {…} }
​​
Properties: Object { TechnicalName: "Cnd_80C34133", Id: "0x0100000000000232", Parent: "0x0100000000000212", … }
​​​
Color: Object { r: 0.5764706, g: 0.75686276, b: 0.8 }
​​​
DisplayName: "GameState.Blarg < 2"
​​​
Expression: "GameState.Blarg < 2"
​​​
ExternalId: ""
​​​
Id: "0x0100000000000232"
​​​
InputPins: Array [ {…} ]
​​​​
0: Object { Text: "", Id: "0x0100000000000234", Owner: "0x0100000000000232" }
​​​​​
Id: "0x0100000000000234"
​​​​​
Owner: "0x0100000000000232"
​​​​​
Text: ""
​​​​​
<prototype>: Object { … }
​​​​
length: 1
​​​​
<prototype>: Array []
​​​
OutputPins: Array [ {…}, {…} ]
​​​
Parent: "0x0100000000000212"
​​​
Position: Object { x: 675, y: 100 }
​​​​
x: 675
​​​​
y: 100
​​​​
<prototype>: Object { … }
​​​
ShortId: 2160279859
​​​
Size: Object { w: 225, h: 100 }
​​​
TechnicalName: "Cnd_80C34133"
​​​
Text: ""
​​​
ZIndex: 7
​​​
<prototype>: Object { … }
​​
Type: "Condition"
​​
<prototype>: Object { … }
​
length: 1
​
<prototype>: Array []
[index-494a6fb0.js:28479:13](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:49:21.504 boolean true [index-494a6fb0.js:13276:13](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:49:21.504 result true [index-494a6fb0.js:28517:19](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:49:21.507 processing... GameState.Blarg < 2 [index-494a6fb0.js:13239:17](https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/assets/index-494a6fb0.js)
13:49:21.507 variables updated 
Window https://michaelgreenhut.com/BecomeAGameWriter/Save/FinalConfrontation/
​
GameState: Object { personalMemories: 0, Blarg: true }
SavedByZero commented 10 months ago

You know, against all odds, I think I may have found it and fixed it.

If I guess correctly, these two lines should NOT be storing variables (only processing comparisons):

 case "Condition":
          let result2 = project.CheckNodeConditions(displayNode);
          console.log("result", result2);
          if (result2) {
            setTimeout(() => {
                console.log("selectNode from condition true");
              selectNodeId(props.nodeId, 0, -1);
            }, 0);
          } else {
            setTimeout(() => {
                console.log("selectNode from condition false");
              selectNodeId(props.nodeId, 1, -1);
            }, 0);
          }

So I added a third parameter in selectNodeId, an integer (guess it could have been a bool, but I wanted flexibility) that tells it whether or not vars should be stored, like so:

function selectNodeId(nodeId, outputPinIndex = 0, storeVar = 1) {
    let displayNode = project.GetNodeByID(nodeId);
    if (displayNode.Properties.Expression != void 0 && storeVar > 0)
      project.StoreVariablesFromNode(displayNode);
[below here is irrelevant...]

What I did was write -1 to that third parameter when conditions used selectNodeId, and leave it as-is when the default path called it (which I deduced was when instruction nodes actually want to set something). Make sense?

chad-ld commented 10 months ago

So I made these two examples here based off your image above: articy_git_example_01 articy_git_exmple_02

I exported them, and published them here: https://dev.chadbriggs.com/articy/testing/gi/index.html https://dev.chadbriggs.com/articy/testing/gi02/index.html

Far as I can tell, they both seem to flow fine, no errors? I didn't do your example exactly as I couldn't quite make out some of the condiditionals in the image, but mine seemed close enough? Let me know if I'm missing something.

SavedByZero commented 10 months ago

Differences...let's see. My global variables have a set name GameState and an integer named Blarg that defaults to 0. I have everything inside a dialogue element called TestyMcTestFace. The first node in that element is the HTMLPREVIEW instruction, which then connects to an instruction setting GameState.Blarg = 2. That connects to a conditional checking if it's less than 2, with positive and negative outcomes. Then I repeat the process and check again, checking if it's still less than 2, after those outcomes.

The reason why I think your test passed is because it's setting a variable to 99 and only checking if it's equal (test 1), and setting it to 98 and checking the positive first (test 2). Try doing my exact steps with the negative being the first outcome (set it to 2, then check to see if it's less than 2). Otherwise I'd have to compare your StoreVariableFromNode method and the method that calls it (and the one that calls that), with my copy.

SavedByZero commented 10 months ago

Also, your second live example still shows this behavior, which for now is giving you positives, but I suspect would eventually fail once it hits a negative:

processing... RNDVariables.GitVar=98; [index-494a6fb0.js:13239:17](https://dev.chadbriggs.com/articy/testing/gi02/assets/index-494a6fb0.js)
13:15:28.754 variables updated 
Window https://dev.chadbriggs.com/articy/testing/gi02/index.html
​
RNDVariables: Object { Option01Discussed: false, EndingVariable: false, nevertruevar: false, … }
​​
EndingVariable: false
​​
GitVar: true

and after the second check, GitVar gets set to false. What would happen with a third check of GitVar > 99?

TLDR: my hypothesis is: GitVar gets set to 98, as intended GitVar < 99 returns true, which then populates the value of GitVar to "true" GitVar > 99 is now true>99, which returns false (tried it in the console to be sure, since that one I wasn't 100% on).
the end result is a false positive for your test. :(