There are training materials available--from books to videos to tutorials--including free videos on You Tube.
It might also help to realize that most script steps correspond to menu options that you can select manually and the menu options usually use the same dialog boxes as the script steps for setting up the details of each selected action. So if you can manually perform a task and just note down each step taken manually, you have probably outlined the steps to put into a script as well.
1. Local variables start with a single $ in their name. Globals have two. A local variable exists and retains an assigned value only as long as the script is executing and its value can only be accessed from the script that assigned a value to it. Global variables are global, their value can be accessed from any script or layout in a file and they retain their values as long as the file is open.
2. Those are the names of two global variables.
3. If you enter layout mode, you can select a layout object and use the Inspector's Name box to give it an object name such as "N". Go to Object puts the "focus" on the object named in the script step. If this object is a field, this puts the cursor into the field. If this object is a button, the button highlights and pressing return would be all you need to "click" that button. Tab control, slide control and popover panels will become visible if they are given an object name and go to object puts the focus on them.
4. Since these variables were defined as global variables. Clearing them insures that any other place in your file that refers to these global variables will access a null (empty string) value.
Now you explain it. I fully understand what the script does.