Setting Default Values

In AutoPlay Menu Studio 3.0, actions that returned values allowed you to specify a "default value" that would be assigned to the variable if the action failed.

In AutoPlay Media Studio 4.0, you can still set a default value for an action...but it's done in a slightly different way. Instead of supplying the value in the action's settings, you simply use a "Variable - Set Value" action to assign a default value to the variable first, before the action is performed.

The reason this works is simply that, in AutoPlay Media Studio 4.0, when an action fails, it doesn't return anything.

In other words, if an action is designed to store a return value in a variable, and the action fails, the variable is left completely untouched.

For example, let's say you wanted to read a value from the Registry. The value you're interested in is called "Install Path" and is located at "HKEY_LOCAL_MACHINE\Software\Hella Cool Software Inc\Super Duper Gizmo". If the user has your "Super Duper Gizmo" program installed, this Registry value will contain the path to the folder where the user chose to install it.

You can read this value in from the Registry by using a simple "Registry - Get Value Data" action, like so:

This action will query the Registry for the value, and then store it in a variable named %InstallPath%.

But what if the user doesn't have your "Super Duper Gizmo" program installed? In that case, the action fails, because it cannot find the value that you told it to retrieve. Nothing is returned from the action at all, and the variable, %InstallPath%, remains completely untouched.

NOTE

 

 

 

In order for an action to change the value of a variable, the action has to succeed.

This makes it very easy to set a default value for things. For example, if you were getting the installation path so you could install another program in the same place, you might want to just install it to a standard path if the user doesn't already have your other program installed. In that case, you would just use a "Variable - Set Value" action to set the %InstallPath% variable to the "default" value right before the "Registry - Get Value Data" action, like so:

If the "Registry - Get Value Data" action fails, the default value will be left as "%ProgramFiles%\Hella Cool Software". If the action doesn't fail, though, the value retrieved from the Registry will be stored in the %InstallPath% variable, overwriting the default value that was stored there first.

TIP

 

 

 

When you set a default value, you probably don't need the user to know that the action failed. By default, most actions display an error message when they fail, but you can change this behaviour on the action's On Error tab.

Next: Control Structures