Use of Global Variable in the Experimenter

Use of Global Variable in the Experimenter

borja_lorenzo4278
Advocate Advocate
240 Views
4 Replies
Message 1 of 5

Use of Global Variable in the Experimenter

borja_lorenzo4278
Advocate
Advocate

Hello

I want to understand how the Experimenter (Based Range) works with Global Variables.
Building on the thread in the question below, and to provide context, I’m sharing once again a simplified version of the model with these additional changes, so the unexpected behavior can be reproduced.

The question on which my simplified model is based is this:

Solucionado: Random Ordering of Production Plan as an Experimenter Scenario - Autodesk Community

 

Despite having read many posts on the forum about the Experimenter and Global Variables, I still do not understand why it doesn’t work in my setup.

 

In the model, I have added a GUI with a checkbox button, a Global Variable, and a Model Trigger. By activating the checkbox, I’m able to control the output of items from the conveyor system. This behaves as expected during a direct run of the model, even after resetting. I also included a Custom Code and a Decide in the Process Flow so that the GUI interaction is interpreted properly in the logic.

It’s important to note that I’m using the default value of the Global Variable to trigger the output event.

I know that the Experimenter cannot read GUI elements during its execution, which is why lines 10 and 11 of the Custom Code are two different approaches. What I expected was that, although the Experimenter cannot interpret line 11 (which uses a function that directly reads the interface), it would still be able to read a node using the syntax of line 10. Neither approach has worked. Still, I hoped that even if those two lines were not interpreted, the logic could proceed by taking the initial value of the Global Variable as valid. That did not happen, and the Experimenter produces null results.

borja_lorenzo4278_0-1753858452305.png

borja_lorenzo4278_3-1753858620031.png

 

To make it work, I would need to alter the logic by adding an ELSE clause in the custom code and explicitly assigning a value to the Global Variable, thereby overwriting the initial value—using the syntax from line 10 that reads the checkbox OUT itemcurrent node and checked the checkbox OUT from the GUI. I know how to fix this, but what I want to understand is: why doesn’t the Experimenter work by relying on the default value of the Global Variable, the way it does in a manual run?

I’m attaching both models: one with the ELSE clause and one without.

borja_lorenzo4278_1-1753858527831.png

borja_lorenzo4278_2-1753858546527.png

borja_lorenzo4278_4-1753858775155.png

 

Why can’t the Experimenter use the initial (default) value of a Global Variable?

Am I missing something?

 

 

0 Likes
Accepted solutions (1)
241 Views
4 Replies
Replies (4)
Message 2 of 5

moehlmann_fe
Enthusiast
Enthusiast

You have the same code in the model reset trigger. But that code always uses "getchecked()", so it will always set OUT to 1 without the GUI open. Without the reset code the "itemcurrent()" approach works.

0 Likes
Message 3 of 5

borja_lorenzo4278
Advocate
Advocate

Thanks as always, Félix.🙏

 

Indeed, in the version of the model without the ELSE clause and with the model trigger OnReset disabled, it works.

 

I’d like to confirm if I understood this correctly:

The issue lies solely in linking the value of the global variable to a function that depends on the user interface (such as getchecked()).


For some unknown reason, this causes the process to break, and the logic no longer triggers events correctly — it simply returns null as the output metric, without displaying any error message.

The Experimenter can use the initial value of the global variable to execute the logic. 

I hope this can serve as a reference for others.

 

I'm attaching the corrected version of the model without the ELSE clause.

 

0 Likes
Message 4 of 5

moehlmann_fe
Enthusiast
Enthusiast
Accepted solution

I wouldn't say the process "breaks". But yes, "getchecked()" just returns 0 when the passed in node is not actually a button in an active window. Thus your reset trigger set the global variable to 1.

Message 5 of 5

borja_lorenzo4278
Advocate
Advocate

Exactly — it’s just as you suspected.
And I would also say that the OnReset trigger probably cannot detect whether the node being referenced is a button on an active GUI window. As a result, part of the intended function of that button — which was to preserve the GUI state after a reset — is lost.

By working within this limitation, the Experimenter now does return valid results.
I’m sharing the updated model again, with this new interpretation of the GUI button.

Great learning experience.

Thank you very much, Felix.

0 Likes