Hi Mark,

Thank you very much for your prompt reply.

I tried your script but it seems that its not
case sensitive.

This is what I have come up as my solution.

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
      set pItem = #NotFound
    end if
  end repeat

  if pItem = #NotFound then
    gList.add(inItem)
  end if

end

I renamed the handler that you did with addAnItem
and mine as addItem.  In the Message window...

-- Welcome to Director --

-- Your script at work.
addAnItem("Earth")
put gList
-- ["Earth", "Jupiter", "Mars", "Venus", "Saturn"]

addAnItem("earth")
put gList
-- ["Earth", "Jupiter", "Mars", "Venus", "Saturn", "earth"]

clearGlobals

-- rewind then Play

-- My script at work.
addItem("Earth")
-- 1
put gList
-- ["Earth", "Jupiter", "Mars", "Venus", "Saturn"]

addItem("earth")
-- 1
put gList
-- ["Earth", "Jupiter", "Mars", "Venus", "Saturn"]


Thank you Mr. Jonkman and sorry again for
the inconvience that I have caused you.

Cordially,
John Erazo


> You are doing a lot of additional work to get what is already built into
> Director.
>
> -- 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.


[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