Product: Mingcedar Studio DESIGNER
Set Variable on Click | Mingcedar Studio
Click to update a current-page JavaScript variable for selection or linked displays. This does not write a PLC Tag.
<section id="set-variable" class="docs-block docs-block-intro docs-block-current"> <span class="section-kicker">Interactions</span> <h2>Set Variable on Click</h2> <p>Click to update a current-page JavaScript variable for selection or linked displays. This does not write a PLC Tag.</p> <div class="docs-detail-list"> <article id="set-variable-item-1" class="docs-detail-row"> <strong>Overview</strong> <p>Set Variable on Click updates a current-page variable when clicked. Use it to store a selection, switch views or update component displays. Declare the variable in Page Script first. Use Write Tag or Write Tag Bit for device writes.</p> </article><article id="set-variable-item-2" class="docs-detail-row"> <strong>Field configuration</strong> <p>Drag Set Variable on Click onto the target component, configure the fields below and save. Place each example part in Page Script or its labeled behavior field. Leave Setup Script empty.</p> <ul> <li>Setup Script: preparation area. Read tags, define intermediate variables, do calculations for Value here. May be left empty.</li><li>Variable: the name of the variable to write; the name only, no quotes (e.g. enter pumpStart, not "pumpStart").</li><li>Value: the value to write. It may be a single expression or full JavaScript; if you write multi-line script, you must end it with return.</li><li>Condition: true allows the assignment; false skips it.</li><li>(Optional appearance feedback) show hand cursor when enabled, thicker stroke when enabled, hide when not enabled; visual hints for clickable / not clickable.</li> </ul> <pre class="docs-code-block"><code>// Page Script
var pumpStart = false;
// Set Variable on Click → Variable
pumpStart
// Value
!pumpStart
// Condition
true</code></pre> </article><article id="set-variable-item-3" class="docs-detail-row"> <strong>When to use it</strong> <p>Best when a click should remember a value inside the page and make other elements react to it.</p> <ul> <li>Page state toggle: switch pumpStart between true and false on each click and bind the indicator to that variable.</li><li>In-page view switching: different buttons write viewMode (e.g. 1/2/3), and several layers use visibility behaviors to show or hide based on viewMode.</li><li>Remember a selection: write the currently selected device id into a variable for page text, navigation, or scripts to read.</li> </ul> </article><article id="set-variable-item-4" class="docs-detail-row"> <strong>Limitations and troubleshooting</strong> <p></p> <ul> <li>Do not confuse it with Write Tag: this writes a runtime variable and never reaches the PLC; use Write Tag / Write Tag Bit for the PLC.</li><li>Do not quote the variable name: Variable takes the bare name (pumpStart); quotes or expressions will fail.</li><li>Multi-line Value must return: a single-line expression needs no return, but multi-line logic without return yields no result.</li><li>To make other elements react: writing only refreshes linked behavior state; other elements must bind to and read the same variable name (the variable space is readable via hqVisuDesigner.globals).</li><li>If a click has no effect, check Condition and the variable name, then confirm the configuration was saved and exported.</li> </ul> </article> </div> <div class="docs-note-grid"> <figure id="set-variable-image-1" class="docs-note-card manual-doc-image-card"> <img src="/WEB_img/HQPPT/VariableWriteBehaviorEditorForm.png" alt="Set Variable on Click behavior editor" loading="lazy" decoding="async"> <figcaption> <strong>Set Variable on Click editor</strong> <p>Enter the variable name and the value to write; a click writes it to a page runtime variable for other behaviors to react to.</p> </figcaption> </figure> </div> </section>