42
Chapter 2: Director Scripting Essentials
Checking items in lists
You can determine the characteristics of a list and the number of items the list contains by
using the following methods.
•
To display the contents of a list, use the
put()
or
trace()
functions, passing the variable that
contains the list as a parameter.
•
To determine the number of items in a list, use the
count()
method (Lingo only) or the
count
property.
•
To determine a list’s type, use the
ilk()
method.
•
To determine the maximum value in a list, use the
max()
method.
•
To determine the minimum value in a list, use the
min()
function.
•
To determine the position of a specific property, use the
findPos
,
findPosNear
, or
getOne
command.
The following statements use
count()
and
count
to display the number of items in a list.
-- Lingo syntax
workerList = ["Bruno", "Heather", "Carlos"] -- define a linear list
trace(workerList.count()) -- displays 3
trace(workerList.count) -- displays 3
// JavaScript syntax
var workerList = list("Bruno", "Heather", "Carlos"); // define a linear list
trace(workerList.count); // displays 3
The following statements use
ilk()
to determine a list’s type.
-- Lingo syntax
x = ["1", "2", "3"]
trace(x.ilk()) // returns #list
// JavaScript syntax
var x = list("1", "2", "3");
trace(x.ilk()) // returns #list
The following statements use
max()
and
min()
to determine the maximum and minimum values
in a list.
-- Lingo syntax
workerList = ["Bruno", "Heather", "Carlos"] -- define a linear list
trace(workerList.max()) -- displays "Heather"
trace(workerList.min()) -- displays "Bruno"
// JavaScript syntax
var workerList = list("Bruno", "Heather", "Carlos"); // define a linear list
trace(workerList.max()); // displays Heather
trace(workerList.min()); // displays Bruno
The following statements use
findPos
to get the index position of a specified property in a
property list.
-- Lingo syntax
-- define a property list
foodList = [#breakfast:"Waffles", #lunch:"Tofu Burger"]
trace(foodList.findPos(#lunch)) -- displays 2
// JavaScript syntax
// define a property list
var foodList = propList("breakfast", "Waffles", "lunch", "Tofu Burger");
trace(foodList.findPos("breakfast")); // displays 1
Summary of Contents for DIRECTOR MX 2004-DIRECTOR SCRIPTING
Page 1: ...DIRECTOR MX 2004 Director Scripting Reference...
Page 48: ...48 Chapter 2 Director Scripting Essentials...
Page 100: ...100 Chapter 4 Debugging Scripts in Director...
Page 118: ...118 Chapter 5 Director Core Objects...
Page 594: ...594 Chapter 12 Methods...
Page 684: ...684 Chapter 14 Properties See also DVD...
Page 702: ...702 Chapter 14 Properties See also face vertices vertices flat...
Page 856: ...856 Chapter 14 Properties JavaScript syntax sprite 15 member member 3 4...
Page 1102: ...1102 Chapter 14 Properties...