Javscript stop multiple dialogs

How do I stop another dialog appearing in a javascript button if the button is clicked again.

Set/check a global variable.

Some example code please that I can learn from, this is a new facet of Directory Opus for me, lot to learn :slight_smile:

Set a variable to true:

Script.vars.set("MyVariableName", true)

Test a variable's value:

if (Script.vars("MyVariableName").value)
{
    // ...
}

where does one do this, my first attempt not working,(done before reply)
image

second attempt failing as well,
image

Standalone buttons don’t have a Script object (only script add-ins). But there are also variables you can set on the DOpus object. All scripts can see/set them, so choose a variable name that will be unique.

Okay, getting somewhere it runs with no errors but after debugging (because not working) apparantly this command
image

is not setting the variable, it comes up as

thanks for the help, the buttons/scripts I am using to learn from 'Searcher' and 'PhotoExif' to name two also are not trapping duplicate dialogs.

You've commented out the test for the variable. Your script sets it but never tests if it has been set.

That was for debugging purpose, it has been set to true and further on in the code I test what value it holds
image

then at the end of OnClick it set to false (on exit ?) The dialog should display 'global set' as it has not reached the end yet.

You're testing .Global not .value. Not sure what you expect that to do, or how you expected anyone to give advice on that code in the previous reply, when you hadn't shown us it!

Here is the code on another button, it gives 'False' as output, must be doing something wrong, remember I've just started learning javascript.

function OnClick(clickData)
{
	// --------------------------------------------------------
	DOpus.ClearOutput();
	// --------------------------------------------------------
	DOpus.vars.set("globalvar", true);

		if (DOpus.vars("globalvar").Global)
			DOpus.Output("TRUE");
		else if (!(DOpus.vars("globalvar").Global))
			DOpus.Output("FALSE");
		else
			DOpus.Output("NOT SET");
}

just read your previous post and this works

function OnClick(clickData)
{
	// --------------------------------------------------------
	DOpus.ClearOutput();
	// --------------------------------------------------------
	DOpus.vars.set("globalvar", true);

		if (DOpus.vars("globalvar").value)
			DOpus.Output("TRUE");
		else if (!(DOpus.vars("globalvar").value))
			DOpus.Output("FALSE");
		else
			DOpus.Output("NOT SET");
}

Many thanks @Leo.

Working as intended now :slight_smile:
One slight worry, is there any way of exiting the dialog (apart from the titlebar close and buttons) that might result in the global var not being reset to false at the end of OnClick() ?

Only if you program it that way. Code runs from top to bottom, unless it has branches, so if your code always clears the variable after the dialog closes, then the variable is going to get cleared after the dialog closes.

The only way it wouldn't is if the process crashed or the computer lost power or similar while the dialog was open, but since the variable isn't being persisted to disk it will be reset again when you restart the program/computer.