Why does "when xxx initializes or changes" does not work?

These blocks are in Screen1


These blocks are in Screen2

When I start the program I do get 234245 in Screen2/DataOutputTxt I can see it
Then I click the button and Data1 and Trigger both are changed. The 2 txt boxes in
Screen1 does ensure the change did happen. However on Screen2/DataOutputTxt remains unchanged. I tried with navigate to block that did not help. Is there a “refresh” kind of button one needs do? Or what am I missing? Kindly advice.

I don’t think the when variable initializes or changes block will work across screens. I think it needs to be on the same screen as the set variable block. Because the moment when the variable value changes is on Screen1 so the Screen2 code is not running. And then when you navigate to Screen2, the change has already been made so there are no changes to detect at that point.

Is the Trigger variable going to have more than two possible values? If not, you could just check its value when the screen opens instead of monitoring it for changes and use a simple if/then/else block. If so, another way to do this is to have a variable called TriggerPreviousValue. Right before you change Trigger’s value, set TriggerPreviousValue to the current value of Trigger. Then, when Screen2 opens, check to see if Trigger ≠ TriggerPreviousValue which would indicate a change in value. Regardless of the result there, set TriggerPreviousValue to Trigger’s value at that point.

You might be right. However please note that when I start the program before pressing the button as mentioned above Screen2/DataOutputTxt gets written with 234245 which means that the when(app variable Trigger) block did get activated and set(DataOutputTxt) did get set. That means it works for the very first time then on the control transition between Screens does not seem to happen. My point is the variable is common for the app as per definition so anywhere in the app a change in the global variable should be felt. Please let me know what am I missing.
Now the reason why I want to do this is, I want to run my big long program on Screen1 and save the trace messages in Screen2. I am using the trick you shared yesterday and storing the executed path every step in a List Data on Screen2. That is the big picture. I will be constantly changing the value of Trigger during the execution and every time that happens a new appropriate message gets pushed to the List Data. In that way we have the full trace execution just as in a C++ program.

I think this is because app variable Trigger is changing value when the screen starts. Variables are initially null so if you initialize the value of Trigger to 1, it’s changing from null to 1 so it activates the monitoring block.

So yes, if you change a variable’s value, it’s a global change but the monitoring block is not a global function. It only works on Screen2.

It makes more sense now that you are explaining the context for all of this. Why not just save the Trigger value to a data source as a new row every time it changes value? Because the thing is… you have control over the Trigger value. If you set it to something else, create a new row with that value. I know it’s not exactly the same as you are wanting but at least you can have a database that looks something like this, and you could always add a column for a timestamp as well:

1
1
1
2
1
2
2
1

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.