Context for command in script function

How come the result of running a command via a script function and a raw command does not do the same thing to the button icon? Is this a context or scope issue? For example, the icon in the one on from the script function does not change. Ironically it does change the one that is not from the script function, but not its own. How can this be changed in the script function to the correct context to affect the icon, or can it?

function OnClick(clickData) {

	cmd = clickData.Func.Command
	cmd.AddLine("@toggle:if $glob:DragIsMove")
	cmd.AddLine("@set $glob:DragIsMove")
	cmd.AddLine("@set $glob:DragIsMove=true")



This code in the raw function does everything I want, even changes the icon.

@toggle:if $glob:DragIsMove
@set $glob:DragIsMove
@set $glob:DragIsMove=true

Take the second code box (the raw function code) and put it into the Modifiers tab when editing the script/button.

(That's what the Modifiers tab is for. It is a place to put any @modifiers that will affect how the button looks or behaves,, and which can't be part of the script itself as they aren't valid JScript or VBScript code.)

Command objects inside of scripts are completely separate things to the script/button itself. (You could create and have 50 different Command objects inside the same button.) They also only exist when the script is actually run, like the difference between an assembly line (the script) and a car (the cmd object the script builds when it runs).

When you use the Resources Tab the dialog properties can be referenced in the Scrip Tab. Now that I understand the Modifiers Tab, my question is can these Modifiers be made dynamic from the syntax in the Script Tab? Thanks

The modifiers themselves can't be changed except by editing the button. (Allowing script code to be used in place of modifiers would mean running scripts constantly to update all the toolbar buttons, which we think would harm performance too much.)

But you can make the button's state dynamic by using modifiers that refer to variables, and have the script change the variables when it runs, if you want the script to be able to change its icon or similar. Use the UpdateToggle method on the Command object which is passed to the script to tell Opus you want the button to be re-evaluated.

That help was perfect, I am able to create scripts that cycle through and activate global variables. Of course disabling the ones not in use. The icons work perfectly also. Thanks

1 Like