Hi John

You are doing a lot of additional work to get what is already built into
Director.

You example:

> on addItem inItem
>   global gList
>   set totalCount = gList.count
>   repeat with i = 1 to totalCount
>     put inItem = gList[i]
>     if inItem = gList[i] then
>       alert "Item already exist."
>       return VOID
>     else
>       gList.add(inItem)
>       exit repeat
>     end if
>   end repeat
> end

could be reduced to the following

on addItem inItem
        global gList
        intAlreadyPresent = gList.findPos(inItem)
        if (Not intAlreadyPresent ) then
                gList.append(inItem)
        end if
         return intAlreadyPresent
end addItem

or if both the startMovie handler and the addItem handler are located in the
same movie script
-- movie script starts here
global gList

on startMovie
  set gList = ["Earth","Jupiter","Mars","Venus","Saturn"]
end

on addItem inItem
  intAlreadyPresent = gList.findPos(inItem)
  if (Not intAlreadyPresent ) then
    gList.append(inItem)
  end if
  return intAlreadyPresent
end addItem

-- movie script ends here

the return value is an integer representing the location in the list where
the item exists, or 0 if not found. It definitely cuts out the ugly repeat
loop since it does the work for you in 1 line.

Hope this helps you

Sincerely

Mark

--------------------------------------------
Mark R. Jonkman
Mark R. Jonkman Consulting
ADDRESS: 20 Windermere Crt., Guelph, ON, CANADA N1E 3L4
PHONE: 519-837-8509
EMAIL: [EMAIL PROTECTED]
--------------------------------------------


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

Reply via email to