Articles Archive
Articles Search
Director Wiki
 

keyDown Navigation with Logic

August 27, 2000
by Pat McClellan

Dear Multimedia Handyman,

I am trying to set up a movie in which the user can go to three interactive pieces in any order by keyDown. After the user has seen all three pieces, the movie should continue to the next section of the movie automatically. What Lingo should I use for this?

Caroline O'Sullivan
Dublin City University

Dear Caroline,

There are two separate pieces to this task. First, you have to set up a keyDownScript that will take the user's input and interpret it to navigate to the appropriate section. Since the user isn't entering text into a field or Text member, you won't use a keyDown handler. Instead, assign a keyDownScript in the startMovie handler. For this article and the demo, I'll assume that you're sitting on some kind of a menu screen. The user can press "A", "B" or "C" to move to frames called "sectionA", "sectionB" and "sectionC" respectively.

on startMovie
  set the keyDownScript to "navigate"
end


on navigate

  case the key of
    "a": go to frame "sectionA"
    "b": go to frame "sectionB"
    "c": go to frame "sectionC"
  end case

end

The startMovie handler assigns a keyDownScript called navigate. That means that whenever a key is pressed, the on navigate handler will execute. In this case, all it does is check to see if the key pressed was "a", "b" or "c". (The key property is not case sensitive.)

So far, you've allowed the user to view sectionA, sectionB, and sectionC in any order, returning to the menu at the end of each section. Now, for the second part of your challenge, let's assume that there is also a sectionD to this movie. After the user has viewed sectionA, sectionB and sectionC, they should automatically go on to sectionD, rather than returning to the menu. This means that the logic operating at the end of A, B and C is something like this (pseudo-Lingo):

if (the user hasn't visited A) or (the user hasn't visited B) or (the user hasn't visited C) then
   go back to the menu so that the user has that option
else
   go on to section D
end if

Here's a demo to show you the full functionality.

Director 7 download for Mac or Windows.

Make sense so far? There are all kinds of ways to track whether the user has been through a section. The easiest (and least elegant) is to set up a global variable for each section. We'll call them gVisitedA, gVisitedB, and gVisitedC. Using those global variables, the frame script at the end of sections A, B and C will look like this:

global gVisitedA, gVisitedB, gVisitedC

on exitFrame

  if (not gVisitedA) or (not gVisitedB) or (not gVisitedC) then
    go to "menu"
  else
    go to "sectionD"
  end if

end

In this script, I've created a compound if statement using the boolean operator OR. It looks to see whether any of the three global variables is false (that's what the "not" means). If any of them are false, then you know that the user hasn't visited that section, and so they're returned to the menu. Of course, you'll have to set those global variables to TRUE when the user goes to that section. This is the frame script that needs to go in the first frame of sectionA:

global gVisitedA

on exitFrame
  gVisitedA = TRUE
end

It's really simple. Just make similar scripts for your other sections.

The last thing you'll need to do is to make some changes to the startMovie script and the navigate handler. The startMovie script will need to initialize the global variables and set them to FALSE. (This doesn't have to happen in the startMovie script, but it's as good a place as any.) The navigate handler will now need to check the global variables so that the A, B and C keys are only functional before all three have been visited.

global gVisitedA, gVisitedB, gVisitedC

on startMovie

  clearGlobals

  gVisitedA = FALSE
  gVisitedB = FALSE
  gVisitedC = FALSE

  set the keyDownScript to "navigate"

end


on navigate

  if not gVisitedA or not gVisitedB or not gVisitedC then
    
    case the key of
      "a": go to frame "sectionA"
      "b": go to frame "sectionB"
      "c": go to frame "sectionC"
    end case
    
  end if

end

That accomplishes what you described in your question, but there's one thing that bugs me. Currently, the user can go back to sections A, B and C repeatedly, until all three have been visited. Maybe that's what you want, but I would expect that the user could view those sections in any order, but only once per section. If that's the functionality you need, then you need to alter the navigate handler like this:

global gVisitedA, gVisitedB, gVisitedC

on navigate

  case the key of
    "a": if not gVisitedA then go to frame "sectionA"
    "b": if not gVisitedB then go to frame "sectionB"
    "c": if not gVisitedC then go to frame "sectionC"
  end case

end

That should take care of your needs. Using global variables like this isn't terribly elegant because they're vulnerable to being set from any script anywhere. On the other hand, they're easy to use and simple to understand. Good luck with your program.

Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2024, Director Online. Article content copyright by respective authors.