SetVar - a script command to set, toggle or delete DO variables from anywhere (buttons, scripts or external applications with dopusrt.exe). It does update buttons as well.
This is like an extended version of the built-in @set command or scripting Vars objects.
Description:
You can use this command to handle global variables in buttons more easily.
Another usecase is to set/delete/toggle variables from external applications, so you can trigger button states and icons or script behaviour from outside of DO.
Features & Params:
SET/S,DELETE/S,TOGGLE/S,EXISTS/S,NAME/K,PERSIST/S,DEPERSIST/S,NOCREATE/S,NOSET/S,TOGGLEHIGH/K,TOGGLELOW/K,TOGGLEDEL/S,GLOBAL/S,LISTER/S,SOURCE/S,DEST/S,VALUE/R,
-
SET, set a variable (default operation)
-
DELETE, delete a variable
-
TOGGLE, toggle a variables value
-
EXISTS, check variables existence
-
NAME, name of the variable
-
VALUE, value to set (make sure its always the last parameter if used)
-
PERSIST, switch variable to persistent
-
NOPERSIST, switch variable to non-persistent
-
NOCREATE, do not create a variable if it does not yet exist when setting or toggling
-
NOSET, do not set a value (can be used in conjcuntion with DE/PERSIST e.g.)
-
TOGGLEHIGH, the "high" value when toggling (default = 1)
-
TOGGLELOW, the "low" value when toggling (default = 0)
-
TOGGLEDEL, deletes the variable for "low" toggle state
-
GLOBAL (use global scope, default)
-
LISTER (use lister scope)
-
SOURCE (use source tab scope)
-
DEST (use destination tab scope)
Usage:
To set a variable named "MyVar" to "MyValue":
SetVar NAME=MyVar VALUE=MyValue
To set a lister scoped variable named "MyVar" to "MyValue":
SetVar NAME=MyVar LISTER VALUE=MyValue
To delete a variable named "MyVar" to "MyValue":
SetVar NAME=MyVar DELETE
To toggle a variable named "MyToggle" between the value "0" and "1":
SetVar NAME=MyToggle TOGGLE
To toggle a variable named "MyToggle" between the high-value "exists" and always delete the variable if toggle state is low:
SetVar NAME=MyToggle TOGGLE TOGGLEDEL TOGGLEHIGH=exists
To toggle a variable named "MyToggle" between the value "low" and "high":
SetVar NAME=MyToggle TOGGLE TOGGLELOW=low TOGGLEHIGH=high
To enable persistence of a variable named "MyVar", without changing its value:
SetVar NAME=MyToggle PERISIST NOSET
To test for existence of a variable named "MyVar" (returns 0 for "exists" and 1 for "not found"):
(A button script will be stopped if the command is used with EXISTS and the variable does not exist.)
SetVar NAME=MyToggle EXISTS
//works in scripts as well (while not being very handy)
DOpus.Output("Exists: " + DOpus.Create.Command.RunCommand("SetVar NAME=MyVar EXISTS") );
To set a variable named "MyVar" from outside of DO:
../dopus/dopusrt.exe /cmd SetVar NAME=MyVar VALUE=TheValue
Some more sensible combinations are possible, try them for yourself.. o)
In case you want to "look" at what happens or just learn how to use it, enable the debug output from the script config section.
Installation:
To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
After that the command shall be ready to use in buttons, scripts and externally from dopusrt.exe of course.
Because the scripts filename changed for v0.2:
Remove the former script Command.Generic_SetVariable.js from your /dopusdata/script addins folder!
cya,
tbone
Download:
-
Latest: v0.2.1 - supports automatic updates/scriptwizard:
Command.Generic_SetVar.js.txt (8.14 KB) -
v0.2 - added scope support, command returncodes fixed:
Command.Generic_SetVar.js.txt (7.1 KB) -
v0.1 - initial release:
Command.Generic_SetVariable.js.txt (6.45 KB)