Button changing its own font color

Hello,

I'm trying to create a simple toggle button that changes its own font color when clicked. I'm using a global variable to store the state and an @ifset directive on the button to set the color.

I've set up a two-part system

  1. A Toolbar Button (set to "Script Function") that calls a user command.

  2. A User Command (also a script) that toggles the global variable and then calls Toolbar REFRESH.

The Problem:

The script log confirms that the entire process is working : the button successfully calls the user command, the user command toggles the global variable, and the Toolbar REFRESH command is sent. However, the button's font color on the toolbar never visually changes.

It seems like there's a timing issue where the refresh command isn't forcing the original button to re-evaluate its @ifset condition and redraw itself.

Here is the exact code I am using:

1. Toolbar Button Code (Function Type: Script Function)

// This button's only job is to call the user command.
@ifset:GLOBAL:state_MyButtonState
@color:text=128,0,128
@endif

@script jscript
function OnClick(clickData) {
    var cmd = DOpus.Create.Command();
    cmd.AddLine("ToggleMyButtonVar");
    cmd.Run();
}


2. User Command Code (Named: ToggleMyButtonVar)

@script jscript
function OnClick(clickData) {
    // This command toggles the variable and sends the refresh command.
    var cmd = DOpus.Create.Command();
    cmd.AddLine("Set GLOBALVAR=!toggle:state_MyButtonState");
    cmd.AddLine("Toolbar REFRESH");
    cmd.Run();
}


What is the correct way to force a button to redraw itself and re-evaluate its @ifset directive after its state variable has been changed by a script?

Thank you for your help.

I'm assuming you got this from AI, since it contains a lot of made up things that aren't actually real Opus commands or syntax.

You can do a "toggling color" using just the evaluator - no need for scripts or user commands.

@color:text=$glob:state_MyButtonState?"255,0,255":"default";
=$glob:state_MyButtonState=!$glob:state_MyButtonState;return "@toggle:update";
2 Likes

Ty!