Articles Archive
Articles Search
Director Wiki

Calendar functions

November 7, 1999
by Pat McClellan

Dear Multimedia Handyman,

We are trying to create a screensaver which moves to a different section either every month or on specific dates. We are graphic designers not Lingo specialists but we need to know if a simple lingo script could produce this. For example jumping to a particular marker in a movie with relevant images for Christmas etc. Can you help or point me in the right direction?

Sean Conroy

Dear Sean,

Director 7 has some nifty new date functions which are ideal for this type of application. They all hinge around the built-in property call the systemDate. In the message window (or any Lingo script) you can simply refer to the systemDate, and it will use whatever date the computer's operating system is set to. Try this in your message window (of course, the date will vary based on when you're doing this.)

today = the systemDate
put today
-- date( 1999, 11, 5 )
put today.month
-- 11
-- 5
put today.year
-- 1999

Or, if you're not happy using Director 7's new dot syntax, you can refer to the properties like this...

today = the systemDate
put the month of today
-- 11
put the day of today
-- 5
put the year of today
-- 1999

Now that we know we can find out the date, let's see how we can apply that to your situation. I'm going to assume that since you're a graphic artist, the calendar pages are graphics and we won't need to do any real calendar functions. Also, rather than use a script that swaps a bunch of cast members, we'll keep it simple: the date will direct us to a frame marker.

A sample movie is available for download in Mac or PC format. This is a Director 7 movie.

For our example, we'll have 4 holidays: Christmas (Dec 25), New Year's Eve (Dec 31), Halloween (Oct 31), and Groundhog Day (Feb 2). I included New Year's Eve so that we'd have an example of 2 holidays in the same month. If it's any other date, then the movie will simply default to the frame showing the entire month.

We obviously want the calendar to go immediately to the correct frame, so we'll put our script in a startMovie handler.

on startMovie
  today = the systemDate
  theDay =
  thisMonth = today.month
  case thisMonth of
    1: go to frame "Jan"
      if theDay = 2 then
        go to frame "GroundhogDay"
        go to frame "Feb"
      end if
    3: go to frame "Mar"
    4: go to frame "Apr"
    5: go to frame "May"
    6: go to frame "Jun"
    7: go to frame "Jul"
    8: go to frame "Aug"
    9: go to frame "Sep"
      if theDay = 31 then
        go to frame "Halloween"
        go to frame "Oct"
      end if
    11: go to frame "Nov"
      if theDay = 25 then
        go to frame "Christmas"
      else if theDay = 31 then
        go to frame "NewYearsEve"
        go to frame "Dec"
      end if
  end case

All this script does it grab the system date, assign values for theDay and theMonth, and then check those values to give the command to go to the right frame.

There's one other script I'm using here, which simply puts the date into a field or text member. Instead of using the systemDate though, I'm going to use an older Lingo property called the long date. The long date returns the date, but it is in string format and includes the day of the week and the month's name (rather than just the month's number.) Here's the behavior that you can drop on any field or text member.

on beginSprite me
  myMem = sprite(me.spriteNum).member
  myMem.text = the long date

Good luck with your calendar programs. You might also want to check out the great Text member calendar behavior that James Newton wrote. It's in the Director 7 behavior library.

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-2017, Director Online. Article content copyright by respective authors.