Can someone help me with a toggle script?

i am triying toggle the sort order by hotkey, here is my code

thanks :slight_smile:



One problem I see immediately is that if SORTREVERSE is On when you click the button, the first @if:Set is true and SORTREVERSE is turned off.

But now that it's off, the next @if:Set is true already so it gets turned on right away. [Edit: Leo's reply below corrects my false information.] May I suggest a simpler command? You only need this one line to accomplish the task.


For the sake of learning, you probably wanted this instead:


(Note, I switched the initial @ifset: to @if:set because I like how it matches with the @if:else.)

Your code seems to work fine as-is.

What problem are you having with it?

@if, @ifset, etc. don't work like that. They will be evaluated before anything in the button runs. (Where side-effects are desired, you can sometimes explicitly update things, but it's not the way they usually work.)

That said, your version is better since it avoids doing the test twice.

Hey Thanks!

I am new to the worl of programming but have been learning fast.

in this example is toggle being used as a true/false 1/0 statement?
if so that is cool. I can see this being very usefull.


I can see where I went wrong with this example. Thanks so much once again!

It was not doing anything. I even tried setting the opposite sort by right click > sort by but trying the hotkey again did nothing.

Ah, I think I know why it wasn't working for you. Are you using Opus 12.20 (latest "stable" rather than latest "beta")?

We tidied up some things in a recent beta which make more of the SORTREVERSE=off-style tests work. Your original button works OK in the newer beta versions (and will work in 12.21 once it's released), but not in 12.20.

Great :smiley:

Thats clears things up. Looking forward

And yes I am using the latest stable release, looking forward to the next shiny stable release now

1 Like

It's just a simple toggle that switches from "on" to "off" or from "off" to "on" depending on the state of that setting at the moment.

Feel free to wait for the next stable release, but since you are stretching your power-user wings, I recommend the beta version. I can't recall a beta that's been horrible for anyone because Jon and Leo do such a good job of vetting things. In fact, I'd go so far as to say that DOpus betas are as solid as most other developer's "stable" releases.

Dangnabbit. I keep forgetting about that. I think of it as a normal top-to-bottom execution. Thanks for reminding me.