Example:
Verifying a password (advanced)

Actions used:

Application - Exit

Control Structure - ELSE

Control Structure - END IF

Control Structure - END WHILE

Control Structure - GOTO

Control Structure - IF

Control Structure - LABEL

Control Structure - WHILE

Dialog - Get Information

Dialog - Message Box

Global List - Find

Page - Jump

Variable - Set Value

In this example, we'll show you how to verify a password against a list of passwords stored in a Global List. To make things interesting, we'll give the user 3 chances to get the password right. If they do get it right, we'll jump to another page.

Here's what the action list looks like:

First, we use a "Variable - Set Value" action to initialize a variable called %attempts_remaining% to the number of times the user will be allowed to get the password wrong.

Next, we use a "Control Structure - WHILE" action to begin a while loop. It will keep looping as long as there are still attempts remaining...in other words, while %attempts_remaining% is greater than zero. (We'll decrement %attempts_remaining% at the end of the while loop.)

TIP

 

 

 

We could make this test even simpler by removing the "> 0" part, i.e. by using the variable %attempts_remaining% all by itself. Since any integer value above 0 is considered "true" in a conditional expression, the while loop would perform exactly the same...looping while %attempts_remaining% was greater than 0, and stopping as soon as it reached 0 and resolved to "false".

All of the actions from this WHILE action to the END WHILE action that follows a little further down will be performed on each "trip" through the while loop.

Next, we use a "Dialog - Get Information" action to ask the user for their password.

Whatever the user types will be stored in a variable called %EnteredText%.

Note that we've enabled the Mask field as password option so the text that the user types will be hidden by asterisks, like so: *******. That only affects what is displayed on the screen, however; the %EnteredText% variable will still contain the text that was actually typed by the user.

Next, we use a "Global List - Find" action to search through our Global List (which we named "Passwords") for an item that matches the text that the user typed. (We set up this Global List in advance, with a single password in it just for this example.)

If a matching item is found in our list of passwords, the "Global List - Find" action will return the index of the matching item. If no matching item is found, the action will return "-1" instead. (This value will be stored in a variable which we've named %ItemIndex%.)

All we need to do to find out if the user entered a valid password is to compare this index with "-1". If it's -1, their password didn't match any of the ones in our list, and it isn't a valid password.

So, we start an IF block with a simple "Control Structure - IF" action that compares the value stored in %ItemIndex% with "-1".

If this expression is true—if %ItemIndex% is indeed equal to -1—then the user entered an invalid password.

Now, we want the user to be able to try again if they have any more attempts remaining. So, we'll start another IF block to test whether the user has any tries left. Because this IF block is located "inside" another IF block, we'll call it the "inner" IF block. (Another name for this kind of IF-within-an-IF is a "nested IF.")

Since we decrement %attempts_remaining% at the end of our while loop, on the last trip through the loop, %attempts_remaining% will contain a value of 1. This means that the user still has at least one more chance if the value in %attempts_remaining% is greater than 1.

In this inner IF block, we use a "Dialog - Message Box" action to prompt the user to try again if they still have any tries left.

Then, we use a "Control Structure - ELSE" action to split the inner IF block into two parts: a "true" part for when the user still has chances left (which we just handled), and a "false" part for when this was the user's last chance to get the password right.

In the false part of this IF block, we use a "Dialog - Message Box" action to let the user know that they've blown all of their chances already:

...and then we use an "Application - Exit" action to exit from the AutoPlay application.

That's it for our "password failed" test...so we end the inner IF block with a "Control Structure - END IF" action.

Next, we use another "Control Structure - ELSE" action to split the outer IF block into two parts: a "true" part for when the password is invalid (which we've already taken care of), and a "false" part for when the user actually got the password right. (If that seems a bit backwards to you, remember that we're testing the result of a search through our Global List of passwords for a "password not found" situation...which is true when the password is invalid, because it wasn't found in the Global List, and false when the password is valid, because it was found in the Global List.)

In this case, we use a "Control Structure - GOTO" action to exit from our while loop...jumping out of the loop to a label called "Password is valid" that we'll add in a moment.

The rest of the "valid password" situation will be handled later in the action list, on the lines immediately following our "Password is valid" label.

At this point, we end the outer IF block with a "Control Structure - END IF" action.

Next, we use a "Variable - Set Value" action to decrement our %attempts_remaining% variable. In other words, we decrease its value by 1, so that if it was 3, it will be 2, and if it was 2, it will be 1, etc.

This is very, very important, because our while loop is designed to keep looping until this variable reaches 0. If we forgot to decrement %attempts_remaining%, the while loop would keep going on forever.

Next, we mark the end of our while loop with a "Control Structure - END WHILE" action. When AutoPlay reaches this END WHILE action, it will jump back up to the WHILE action that started the loop, and test that WHILE action's expression all over again. If the expression is still true, the loop will happen again...and if the expression is false, AutoPlay will jump back to the next line after this END WHILE action, and continue from there.

Now we're outside of the while loop, so we use a "Control Structure - LABEL" action to give our GOTO action somewhere to go to. (Remember that the GOTO action is being used to jump out of the while loop when the user gets the password right.) Notice that we've chosen a name for our label that describes the situation when it will be jumped to. This is always a good idea, in case we need to add other labels to this action list (so we can tell them all apart).

And, in fact, this is where we will handle the "password is valid" situation. First, we use a "Dialog - Message Box" action to tell the user they got it right.

Then, finally, we use a "Page - Jump" action to jump to a page called "Password protected page".

Whew!

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

(See if you can figure out what the password is :)