SetState - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

DocumentTools[Canvas][Script]

 SetState
 set hidden canvas state

 Calling Sequence SetState(script,value)

Parameters

 script - DocumentTools:-Canvas:-Script object value - expression, string, or other value

Description

 • The SetState command records a string property that can be fetched by GetElements. This allows you to query and update hidden values in a canvas-based application.

Examples

In this example, the number of times the Press button is pressed is stored behind the scenes, and only revealed when the Show Count button is pressed. The initial state of 100 is given in the constructed canvas by a call to the State command.

 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Canvas}\right):$
 > Press := proc(canvas)    local state := GetElements(canvas,"state");    local sc := Script();    SetState(sc,1+state[1]:-value);    ToString(sc); end proc:
 > Show := proc(canvas)    local M := GetElements(canvas,'custom'="Input");    local state := GetElements(canvas,"state");    local sc := Script();    SetActive(sc,M[1]);    SetMath(sc,state[1]:-value);    ToString(sc); end proc:
 > $\mathrm{cv}≔\mathrm{NewCanvas}\left(\left["Counter",\mathrm{Math}\left(0,'\mathrm{custom}'="Input"\right),\mathrm{ScriptButton}\left("Press",\mathrm{Press}\right),\mathrm{ScriptButton}\left("Show Count",\mathrm{Show}\right),\mathrm{State}\left(100\right)\right]\right):$
 > $\mathrm{ShowCanvas}\left(\mathrm{cv}\right)$

Compatibility

 • The DocumentTools[Canvas][Script][SetState] command was introduced in Maple 2022.
 • For more information on Maple 2022 changes, see Updates in Maple 2022.