• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Lesson 26. Using a List Database > Combining Your Work into a Handler

Combining Your Work into a Handler

Now you will use all of the Lingo elements you've been testing in the Message window, stringing them together into one handler that determines the current view and direction of the scene, sets the new view and direction, and then displays the graphic. The handler will also move the highlight to the sprite the user clicked.

1.
Open the movie script and add the lines shown in bold:

global gLocationList, gCurrentView      --Declare these as global variables.

on startMovie                           --At the start of the movie, do the following:
  CreateLocationList                    --Run this handler to create the location list.
  gCurrentView = "vict.n"               --Set the northern view of Victoria as the default.
end

on CreateLocationList                   --startMovie calls this handler.
  gLocationList = [:]                   --Declare an empty property list.
  setaProp(gLocationList, item 1 of line 1 of field "Location codes",}
  Item 2 of line 1 of field "Location codes")
                                        --Insert the first item in line 1 of the field into
                                        --the property list, gLocationList.
                                        --This is the property.
                                        --Insert the second item of
                                        --the field into the list as the data
                                        --associated with that property.
  setaProp(gLocationList, item 1 of line 2 of field "Location codes",}
  item 2 of line 2 of field "Location codes")
                                        --Insert the first item in line 2 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list as the data
                                        --associated with that property.

  setaProp(gLocationList, item 1 of line 3 of field "Location codes",}
  item 2 of line 3 of field "Location codes")
                                        --Insert the first item in line 3 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
  setaProp(gLocationList, item 1 of line 4 of field "Location codes",}
  item 2 of line 4 of field "Location codes")
                                        --Insert the first item in line 4 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
  setaProp(gLocationList, item 1 of line 5 of field "Location codes",}
  item 2 of line 5 of field "Location codes")
                                        --Insert the first item in line 5 of the field into
                                        --the property list, gLocationList.
                                        --Insert the second item of line
                                        --of the field into the list.
end

on SetPlace thePlaceName, theSprite
							--When a location name is clicked, the name
							--of the location and the sprite number are
							--sent as parameters.
							newView = getaProp(gLocationList, thePlaceName)
							--Get the data associated with thePlaceName
							--in the gLocationList property list. Then set
							--newView to that data. The data is a code
							--for a particular location.
							oldDirection = (gCurrentView).char[(gCurrentView).chars.count]
							--Get the last character of gCurrentView. This
							--will be a direction letter. Then set
							--oldDirection to that letter.
							gCurrentView = newView&"."&oldDirection
							--Concatenate newView and oldDirection and
							--place a period between them. This results
							--in the name of a cast member.
							--Set gCurrentView to this value.
							sprite(1).memberNum = member (gCurrentView).number
							--Switch the cast member assigned to
							--sprite 1 with the cast member
							--assigned to gCurrentView.
							sprite(15).rect = sprite (theSprite).rect
							--When a location name is clicked,
							--the sprite number of the location
							--name is sent as a parameter (theSprite).
							--Move the highlight to the sprite that
							--was clicked.
							updateStage                           --Update the stage to show the new view
							--and the new highlight location.
							end
						

					  

Now look at the SetPlace handler.

In the first line, the handler defines two arguments for SetPlace: thePlaceName and theSprite. Recall the script you looked at earlier for cast member 26. This script calls the SetPlace handler and sends the parameter values "white nile" (for thePlaceName) and 5 (for theSprite). You will use these parameters later in the handler.

The second line, newView = getaProp(gLocationList, thePlaceName), creates the newView variable and initializes it to hold the value retrieved from gLocationList by the getaProp command. If the user clicks White Nile, for example, that value would be "wnile": newView = (gLocationList, "white nile").

Next you create a variable, oldDirection, which is set to the last character of the name of the view currently on the stage, contained in gCurrentView. Here is how this line breaks down as it is evaluated by Director:

oldDirection = (gCurrentView).char[(gCurrentView).chars.count]
oldDirection = ("vict.n").char[6]
oldDirection = "n"

Now that you have both the code and the direction, the name of the cast member to be displayed can be determined by concatenating newView and oldDirection. The name is placed in the global variable gCurrentView. In the example, this is how this line breaks down:

gCurrentView = "wnile"&"."&"n"
gCurrentView="wnile.n"

Now you use the memberNum to switch the cast member assigned to sprite 1. Remember that sprite 1 contains the view that is displayed on the stage. In this case, you switch the image contained in channel 1 with the image contained in gCurrentView. This line breaks down like this:

sprite(1).memberNum = member ("wnile.n").number
sprite(1).memberNum =

Next you move the rectangle that highlights the location name to the location name that was just clicked: sprite(15).rect = sprite (theSprite).rect

The value of theSprite was sent as a parameter of SetPlace when the user clicked the White Nile option. Its value is 5. The line for this example breaks down like this:

sprite(15).rect = sprite(5).rect

Remember that the rect contains the coordinates of a rectangle. In this case, it sets the coordinates of the rectangle in sprite 15 (the default position of the rectangle over the Victoria button) to sprite 5 (the White Nile button). Thus, the blue rectangle is set to the same coordinates as White Nile.

Finally, you update the stage to show the changes.

2.
Save your work.

3.
Close the Script window and play the movie. Click any location except Nubia. Don't click a direction on the compass.

Now when you click a location name, the name is highlighted and the appropriate image is displayed. Every button works except Nubia, because all the other locations have scripts. You will create a script for the Nubia button next.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint