Command Reference - Action Examples
|
Actions used: |
In this example, we'll use a "Registry - Set Value" action to store the user's name in the Registry. (For example, so we can access it the next time our AutoPlay application is run without asking the user all over again.)
Here's what the action list looks like:

|
NOTE |
|
|
|
|
|
We set these actions up on our start page's "On Initialize" event, so they will be performed before the page is displayed. |
First, we use a "Registry - Get Value Data" action to get the user name from the Registry, in case this isn't the first time this action script has been performed. (If it is the first time, we'll get the user's name and store it in this Registry location later.)

Note that if this is the first time that this action script has run, our Registry value won't exist yet. In that case, the "Registry - Get Value Data" action will generate an error, because it can't find the Registry value we told it to access. This is actually a good thing, because we can use this error to determine whether or not the value exists.
We don't need the user to be told about the error, though, so we'll change the User Notification settings on the On Error tab for this action from "Verbose" to "None".

This will prevent the action from notifying the user about this error.
Next, we use a "Control Structure - IF" action to find out whether an error was generated. To do that, we just check to see whether the built-in variable %LastErrorNum% is set to "1", which is the error code that "Registry - Get Value Data" stores in %LastErrorNum% if the Registry value doesn't exist.

If an error was generated—if the Registry value didn't exist yet—we want to ask the user for their name and store it in the Registry. So, we use that good 'ole "Dialog - Get Information" action to prompt the user for their name, and store whatever they type in a variable called %UserName%.

Now, that "Dialog - Get Information" action will present the user with a dialog that looks something like this:

Now, what if the user is a paranoid fruitcake, and decides to press the Cancel button? In that case, instead of storing the text that the user typed in, the "Dialog - Get Information" action will store the word "CANCEL" in our variable to indicate that the Cancel button was pressed.
So, in order to avoid storing "CANCEL" in the Registry as the user's name, we use another "Control Structure - IF" action to determine whether the user pressed "Cancel".

The <> operator is the same as saying "is not equal to," so this conditional expression will be true if %UserName% is anything but "CANCEL". In other words, it will be true if the user pressed OK, and false if they pressed Cancel.
(Hopefully none of our users go by the name "CANCEL"... :)
If user pressed OK, we use want to store the text that they entered in the Registry, so we can retrieve it the next time this action script is performed. We can do this easily with a "Registry - Set Value" action.

Then, we use a "Control Structure - ELSE" action to split this inner IF block into two parts: a "true" part for when the user pressed OK (which we just handled), and a "false" part for when the user pressed Cancel.
If the user pressed Cancel, %UserName% currently holds "CANCEL", so let's change that to something a bit more appropriate. It's tempting to change the name to something like "Identity Theft Attempt Failed!", but we'll behave ourselves for this example and just set the user's name to "<name unknown>".
This is easily done with a "Variable - Set Value" action to replace the current contents of %UserName% ("CANCEL") with our default text.

Next, we use a "Control Structure - END IF" action to end our inner IF block, followed by another "Control Structure - END IF" action to end the outer IF block. (Notice the different levels of indentation we used to make it obvious which actions are in each IF block.)
Finally, we use a "Text Object - Set Text" action to write a short greeting that includes the user's name in the Text Object named "Text - Greeting" on our page.

Here's a link to the finished example, as an AutoPlay Media Studio 4.0 project: