On 6/29/05 10:04 AM, "Duck" <[EMAIL PROTECTED]> wrote:
> if getPlayerVersion()>=10 then
> g.timeOutObj = timeOut().new("Timeout name", period, handler, targetObject)

Hi Ben,

To be rigorous, you'd also have to check whether that the
scriptExecutionStyle is not set to 9.  Here's a handler that takes care of
that:

on mxTimeOut(me, aName, aPeriod, aHandler, aTarget, aStartTime) -------
  -- INPUT: <aName> string name of timeOut object to create
  --        <aPeriod> minimum time between callbacks, in milliseconds
  --        <aHandler> symbol handler to call
  --        <aTarget> object containing the callback handler
  --        <aStartTime> value of milliseconds when first callback is
  --         to be made
  -- ACTION: Creates a new timeOut object, regardless of the version
  --         Director (8.0 or greater).
  --         If aStartTime is an integer, delays the first callback
  --         until after the given time
  -- OUTPUT: Returns a timeOut object.
  --------------------------------------------------------------------
  
  vVersion = getPlayerVersion()

  if vVersion < 10 then
    -- DMX or earlier
    vTimeOut = timeOut(aName).new(aPeriod, aHandler, aTarget)
    
  else if the scriptExecutionStyle = 9 then
    -- DMX 2004 or later in DMX emulation mode
    vTimeOut = timeOut(aName).new(aPeriod, aHandler, aTarget)
    
  else
    -- DMX 2004 or later
    vTimeOut = timeOut().new(aName, aPeriod, aHandler, aTarget)
  end if
  
  if integerP(aStartTime) then
    vTimeOut.time = aStartTime
  end if
  
  return vTimeOut
end mxTimeOut


> It returns the player version as a float, so it can be numerically compared
> (which is sometimes not possible with certain player versions, such as:
> "10.0.3". It discards any revision numbers after the second period.
> 
> on getPlayerVersion
> oid = the itemDelimiter
> the itemDelimiter = "."
> pv = the environment.productVersion
> if pv.item.count <= 2 then
>   playerVersion = value(pv)
> else
>   playerVersion = value(pv.item[1]&"."&pv.item[2])
> end if
> the itemDelimiter = oid
> return playerVersion
> end

Here's a version of your handler which:
* works with all versions of Director from 7.0
* performs no slower than yours on my Mac on all the versions of
  Director that I tried it on (your mileage may vary)
* provides more precise version data

Enjoy,

James

---------------------------------------------------------------------------
  
on getPlayerVersion() ------------------------------------------------
  -- OUTPUT: Returns a floating point number corresponding to the
  --         player version.
  --         Examples: 7.02, 8.51, 8.0, 8.51, 9.0, 10.1
  -- NOTE:   For player versions prior to 8.5.0, the output may be 0.0
  --         or an erroneous value less than 10.0, if the global
  --         variable 'version' has been altered via Lingo.
  --------------------------------------------------------------------
  
  vString = the environment[#productVersion] -- added in 8.5
  
  if not stringP(vString) then
    -- Prior to 8.5.  Try using global version, but it might have been
    -- hijacked and is thus not 100% reliable.
    global version
    
    vString = version
    if stringP(vString) then
      if offset(".", vString) <> 2 then
        -- version is no longer the original string
        return 0.0
      end if
      
    else
      -- version has been altered
      return 0.0
    end if
  end if
  
  -- "7.0.2 | "8.0" | "8.5.1" | "9.0" | "10.1"
  vDelimiter = the itemDelimiter
  the itemDelimiter = "."
  vVersion = vString.item[1..2] -- "7.0", "8.0" "8.5", "9.0", "10.1"
  vVersion = value(vVersion) -- 7.00, 8.00, 8.50, 9.00, 10.10
  
  if the number of items of vString > 2 then
    vSubVersion = vString.item[3]
    vSubVersion = integer(vSubVersion) * 0.01
    vVersion = vVersion + vSubVersion
    -- 7.02, 8.51
  end if
  
  the itemDelimiter = vDelimiter
  
  return vVersion
end getPlayerVersion

[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
lingo-l@penworks.com  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to