@label: does not change when button toggles

I have the following commands in a button:

@if:$glob:LAYOUT
@label:"Desktop"
@set glob:LAYOUT
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Commander JEG Desktop"
@label:"Desktop"
@if:else
@label:"NUC"
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Commander JEG NUC"
@set glob:LAYOUT=on

The LAYOUTs toggle each time the button is pressed but the button always reads "Desktop" and doesn't change when the if clause is triggered, as I thought it would.

What do I need to change? TIA

Same situation here.

I tried this additional first line but it had no effect:

@label:IsChecked("@set glob:LAYOUT=on") ? "Desktop" : "NUC"
@if:$glob:LAYOUT
//@label:"Desktop"
@set glob:LAYOUT
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Commander JEG Desktop"
@label:"Desktop"
@if:else
//@label:"NUC"
@sync:/home\dopusrt.exe /cmd Close
Prefs LAYOUT="Commander JEG NUC"
@set glob:LAYOUT=on

What am I supposed to test for and how do I do it? No documentation exists for @label. A hint, please?

You can test the variable directly:

@label:Val("$glob:LAYOUT")=="on" ? "Desktop" : "NUC"

Don't forget to add

@if:common
@toggle:update

I've been struggling a bit with the @label modifier as well but in a different way. Currently on the 13.6.10 beta.

I've been playing around with a button that has this code below which just toggles between sorting by modified and date. (I know there's probably a more straightforward way to do it with standard functions but I was experimenting with evaluator). Anyway the button works in terms of going between the sorting methods, but the label doesn't change at all from the original label.

My intention is to use eventually $labelText, but that wasn't working, but it doesn't work when I explicitly set it either like is shown below.

{=
	if (IsChecked("Set SORTBY=modified")) {
		$setCommand="SORTBY=name";
		$labelText="Sorting Name";
	} elseif (IsChecked("Set SORTBY=name")) {
		$setCommand="SORTBY=modified";
		$labelText="Sorting Modified";
	} else {
		$setCommand="SORTBY=name";
		$labelText="Sorting Name";
	}
=}

@Output Label Text: {$labelText}
@Output Set Command: {$setCommand}

@label "Test Label String"

Set {$setCommand}

I also tried this which also does not work, again just trying to hard code it. Despite it working when put on a button just by itself.

@evalalways:labelValue="Test Label String"
@label:labelValue

What's confusing me is that the above code DOES work if I put it at the top, before the evaluator block. But obviously I want to do it after all the variables are set so I can use them.

Same reason: the evaluator code block will be ignored until runtime.

@evalalways may help, if you don't want to do everything in a single line.

More detail: Evaluator variables in conditional label assignment - #2 by Leo

Hm I don't really follow. I'm just having trouble understanding how the evaluator block's existence affects the label being set, even if it's not being used in setting the label.

For example take this example button code where I just hard code a label value:

@Output Random Evaluator Example Return: {=
	$test="Blah";
	return "Hello";
=}

@label "Whatever String"
@Output Variable Value: {$test}

This generates an output of this below (just to illustrate that the evaluator block is running), but the label doesn't change for some reason.

Random Evaluator Example Return: Hello
Variable Value: Blah

However, if I just move the label command to the top like this, it does change the button label to 'Whatever String'. (And the output is the same)

@label "Whatever String"

@Output Random Evaluator Example Return: {=
	$test="Blah";
	return "Hello";
=}

@Output Variable Value: {$test}

Edit: Ok I just realized it DOES work and change the label if the evaluator block is all on one line like this:

@Output Random Evaluator Example Return: {=$test="Blah";return "Hello";=}
@label "Whatever String"
@Output Variable Value: {$test}

So not sure if I did something wrong with the syntax or just a bug. Or maybe I'm just using the multi-line evaluator feature in an unintended way.

The issue is that Opus buttons aren't necessarily just a sequential list of commands that are processed one after the other. Some @ directives, like @label, are completely ignored when the button is actually run. Instead they're processed separately at other times as part of the dynamic update system.

When that happens, other lines (those that actually form part of the command that is run when you click the button) get skipped.

This is why we have @evalalways - it lets you provide evaluator code that's processed in both cases (during dynamic update and when the button is run).

Ah ok I think I understand now.

I got it to work by using @evalalways and only using evaluator variables instead of the $ type variables. So at least now I believe all the variables get updated at the same time, whenever that might be.

I did have to do some funky arrangements of the labelText assignments in terms of which if block to put them in, because the label was basically changing to the opposite of what I expected - I guess because of the order of how stuff is happening behind the scenes.

@evalalways:if (IsChecked("Set SORTBY=modified")) {setCommand="SORTBY=name"; labelText="Sorting Modified";} elseif (IsChecked("Set SORTBY=name")) {setCommand="SORTBY=modified"; labelText="Sorting Name";} else {setCommand="SORTBY=name"; labelText=original_label;}

@label=labelText
Set {=setCommand=}

So it works i just wasn't able to get it to work with the multi line but oh well.

I was also able to add in functionality to change the icon as well:

@evalalways:if (IsChecked("Set SORTBY=modified")) {	setCommand="SORTBY=name"; labelText="Sorting Modified"; iconName="setDate"; } elseif (IsChecked("Set SORTBY=name")) {setCommand="SORTBY=modified"; labelText="Sorting Name"; iconName="savedlayoutsedit";} else {setCommand="SORTBY=name"; labelText="Sort Name/Modified"; iconName="sort_alpha";}

@icon: =iconName
@label: =labelText
Set {=setCommand=}

It took me a bit of time to realize that when doing something like @label=Whatever, the equals sign isn't part of the @ modifier but rather to signify what's next is for the evaluator, so it's basically the same as @label:=Whatever

Ixp... exactly where in jinsight's code we need to add these commands?

Place it after the existing lines.

Command modifier reference

You mean at the bottom of the code?

Yes.

1 Like

It worked. Thanks a lot. :smiley: