Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
StuntRacer
Curve Sprite - Move a sprite along a curved path.
encrypt/decrypt Image
Prevent Hour Glass Cursor after AVI Ends
Increase/ Decrease FrameRate of a Flash Member
AutoCropper v1.2
Bitmap text
VolumeController
Rollover Ink Change
Opening and closing a CD-door behaviour
 

 

 

Behavior Linear and Property List AND String functions

Added on 5/15/2001

 

Compatibilities:
D8 Script

This item has not yet been rated

Author: nightboy

Place movie script in your cast. Emulates Javascript list and string functions, more to come.

--B3* LIST FUNCTIONS
--________________________________________________________________________________
--
--When using my list functions, make sure to attach all scripts to your cast.
--
--These functions simulate the traditional array functions of most other programming
--languages. Some of the functions such as sort() are already built into Director.
--I included them as a means of consistent thinking.
--If you find errors or bugs that arise in the scripts please let me know.
--
--brian@imaginarystudio.com
--http://www.imaginarystudio.com
--
--________________________________________________________________________________
--
--
--
--
--For LINEAR LISTS:
--________________________________________________________________________________
--
--•Assume that list = a linear list.
--
--
--SHIFT
---Removes and returns the first element of the list, shifting all subsequent elements down one.
--
--myVariable = list_shift(list)
--
--
--UNSHIFT
---Adds an element to the beginning of the list.
--
--list_unshift(list,myValue)
--
--
--PUSH
---Appends an element to the end of a list.
--
--
--list_push(list,myValue)
--
--
--POP
---Removes the last element of a list and returns the value.
--
--myVariable = list_pop(list)
--
--
--REVERSE
---Reverses the order of the elements of a list. Works with sorted and unsorted lists.
--
--list = list_reverse(list)
--
--
--SORT
---Sorts the elements of a list.
--
--list_sort(list)
--
--
--JOIN
---Concerts all the elements of a list into a string and concatenates them.
--
--myVariable = list_join(list,seperator)  -- seperator is optional
--
--
--SLICE
---Returns a slice or sublist of the specified list. The returned list contains all
-- the elements from the start position up to and not including the end position.
--
--myVariable = list_slice(list,start,end)
--
--
--SPLICE
---Insert and remove elements from a list.
--
--list_splice(list,start,numberOfElementsToDelete,insertElements,...)
--
--
--CONCAT
---Returns a new array formed by concatenating each of the specified arguments to the list.
--
--myVariable = list_concat(list,value)
--
--
--
--
--
--For PROPERTY LISTS:
--________________________________________________________________________________
--
--•Assume that list = a property list.
--
--SHIFT
---Removes and returns the first element of the list, shifting all subsequent elements down one.
--
--myVariable = pList_shift(list)
--
--
--UNSHIFT
---Adds an element to the beginning of the list.
--
--list = pList_unshift(list,myValue)
--
--
--PUSH
---Appends an element to the end of a list. Works with sorted and unsorted lists.
--
--list = pList_push(list,myValue)
--
--
--POP
---Removes the last element of a list and returns the value.
--
--myVariable = pList_pop(list)
--
--
--REVERSE
---Reverses the order of the elements of a list. Works with sorted and unsorted lists.
--
--list = pList_reverse(list)
--
--
--SORT
---Sorts the elements of a list.
--
--pList_sort(list)
--
--
--JOIN
---Concerts all the elements(property values) of a list into a string and concatenates them.
--
--myVariable = pList_join(list,seperator)  -- seperator is optional
--
--
--SLICE PROPERTY
---Returns a slice or sublist of the specified list. The returned list, (a property list), contains all
-- the elements from the start position up to and not including the end position.
--
--myVariable = pList_sliceProperty(list,start,end)
--
--
--SLICE VALUE
---Returns a slice or sublist of the specified list. The returned list,(a linear list), contains all
-- the elements from the start position up to and not including the end position.
--
--myVariable = pList_sliceValue(list,start,end)
--
--
--SPLICE
---Insert and remove elements from a list.
--
--list = pList_splice(list,start,numberOfElementsToDelete,insertElements,...)
--
--
--CONCAT
---Returns a new array formed by concatenating each of the specified arguments to the list.
-- NOTE, value can not = a list or a number.
--
--myVariable = plist_concat(list,value)
--
--
--B3* STRING FUNCTIONS
--________________________________________________________________________________
--
--When using my string functions, make sure to attach all scripts to your cast.
--
--These functions simulate the traditional array functions of most other programming
--languages. Some of the functions such as sort() are already built into Director.
--I included them as a means of consistent thinking.
--If you find errors or bugs that arise in the scripts please let me know.
--
--brian@imaginarystudio.com
--http://www.imaginarystudio.com
--
--________________________________________________________________________________
--
--
--
--
--For STRINGS:
--________________________________________________________________________________
--
--myString = string(value)
--
--SUBSTR
---Returns a substring with a character position and length.
--
--newString = substr(myString, start, length)
--
--
--SUBSTRING
---Returns a substring with a character position start and end.
--
--newString = substring(myString, start, end)
--
--
--SPLIT
---Returns a list of substrings of the specified string. Default delimeter is ",".
--
--newList = split(myString,delimeter)
--
--
--toUPPERCASE
---Converts the characters of a list to uppercase.
--
--myString = toUpperCase(myString)
--
--
--toLOWERCASE
---Converts the characters of a list to lowercase.
--
--myString = toLowerCase(myString)
--
--*Built By Brian


--LINEAR LIST FUNCTIONS

on list_shift  l
  checkLinearListForType(l)
  v = l[1]
  deleteAt(l,1)
  return v
end


on list_unshift  l, v  
  checkLinearListForType(l)
  addAt (l, 1, v)
end


on list_push  l, v
  checkLinearListForType(l)
  append(l,v)
  return
end


on list_pop  l
  checkLinearListForType(l)
  v = l[l.count]
  deleteAt(l,l.count)
  return v
end


on list_reverse l
  checkLinearListForType(l)
  t = []
  lc = l.count
  repeat with i = 1 to lc
    t[i] = l[(lc - (i - 1))]
  end repeat
  return t
end


on list_sort l
  checkLinearListForType(l)
  l.sort()
  return
end


on list_join l,s
  checkLinearListForType(l)
  lc = l.count - 1
  if voidP(s) then s = ","
  t = checkForList(l[1],s)
  if ( l.count = 1) then
    ns = t
    return ns
  else if ( l.count = 2) then
    ns = t & s
    t = checkForList(l[2],s)
    ns = ns & t
    return ns
  else    
    ns = t & s
    repeat with i = 2 to lc
      t = checkForList(l[i],s)
      ns = ns & t & s
    end repeat
    t = checkForList(l[lc + 1],s)
    ns = ns &  t
    return ns  
  end if
  
end


on list_slice l, s, e
  checkLinearListForType(l)
  t = []
  endPoint = endPoint - 1
  repeat with i = s to e
    append(t,l[i])
  end repeat
  return t
  
end


on list_splice l,s,n
  checkLinearListForType(l)
  repeat with i = 1 to n
    deleteAt(l,s)
  end repeat
  repeat with i = 4 to the paramCount
    addAt (l, (s + (i - 4)), param(i))
  end repeat
end

on list_concat l
  checkLinearListForType(l)
  t = []
  e = l.count
  repeat with i = 1 to e
    append(t,l[i])
  end repeat
  e = the paramCount
  repeat with i = 2  to e
    append(t,param(i))
  end repeat
  return t
end



--PROPERTY LIST FUNCTIONS
on pList_shift  l
  checkPropListForType(l)
  v = [:]
  setaProp (v, getPropAt(l, 1), l[1])
  deleteProp (l, getPropAt(v, 1))
  return v
end

on pList_unshift  l, v  
  checkPropListForType(l)
  t = [:]
  lc = l.count
  v =  propCheckMyValueForType(v)
  addProp (t, getPropAt(v, 1), v[1])
  repeat with i = 1 to lc
    addProp (t, getPropAt(l, i), l[i])  
  end repeat
  return t
end


on pList_push  l, v
  checkPropListForType(l)
  t = [:]
  lc = l.count
  repeat with i = 1 to lc
    addProp (t, getPropAt(l, i), l[i])  
  end repeat
  v =  propCheckMyValueForType(v)
  addProp (t, getPropAt(v, 1), v[1])
  return t
end


on pList_pop  l  
  checkPropListForType(l)
  v = [:]
  lc = l.count
  setaProp (v, getPropAt(l, lc), l[lc])
  deleteProp (l, getPropAt(v, lc))
  return v
end


on pList_reverse l
  checkPropListForType(l)
  t = [:]
  lc = l.count
  repeat with i = 1 to lc
    addProp (t, getPropAt(l, (lc - (i - 1))), l[(lc - (i - 1))])  
  end repeat
  return t
end


on pList_sort l
  checkPropListForType(l)
  l.sort()
  return
end


on pList_join l,s
  checkPropListForType(l)
  lc = l.count - 1
  if voidP(s) then s = ","
  t = checkForList(l[1],s)
  if ( l.count = 1) then
    ns = t
    return ns
  else if ( l.count = 2) then
    ns = t & s
    t = checkForList(l[2],s)
    ns = ns & t
    return ns
  else    
    ns = t & s
    repeat with i = 2 to lc
      t = checkForList(l[i],s)
      ns = ns & t & s
    end repeat
    t = checkForList(l[lc + 1],s)
    ns = ns &  t
    return ns  
  end if
  
  
  
on pList_sliceProperty l, s, e
  checkPropListForType(l)
  t = [:]
  e = e - 1
  repeat with i = s to e
    setaProp (t, getPropAt(l, i), l[i])
  end repeat
  return t
  
end

on pList_sliceValue  l, s, e
  checkPropListForType(l)
  t = []
  e = e - 1
  repeat with i = s to e
    append(t,l[i])
  end repeat
  return t
  
end


on pList_splice l,s,n
  checkPropListForType(l)
  t = [:]
  
  s = s - 1
  repeat with i = 1 to s
    addProp (t, getPropAt(l, i), l[i])  
  end repeat
  
  repeat with i = 4 to the paramCount
    p = param(i)
    if ilk(p) = #proplist then
      if p.count > 1 then
        repeat with i = 1 to p.count
          addProp (t, getPropAt(p, i), p[i])  
        end repeat
      else
        addProp (t, getPropAt(p, 1), p[1])  
      end if
    else if ilk(p) = #string then
      addProp (t, symbol(p), "")
    else if ilk(p) = #symbol then
      addProp (t, p, "")
    end if
  end repeat
  
  s = (s + 1) + n
  repeat with i = s to l.count
    addProp (t, getPropAt(l, i), l[i])  
  end repeat
  
  return t
  
end

on plist_concat l
  checkPropListForType(l)
  t = [:]
  e = l.count
  repeat with i = 1 to e
    addProp (t, getPropAt(l, i), l[i])  
  end repeat
  e = the paramCount
  repeat with i = 2  to e
    p = param(i)
    if ilk(p) = #proplist then
      if p.count > 1 then
        repeat with i = 1 to p.count
          addProp (t, getPropAt(p, i), p[i])  
        end repeat
      else
        addProp (t, getPropAt(p, 1), p[1])  
      end if
    else if ilk(p) = #string then
      addProp (t, symbol(p), "")
    else if ilk(p) = #symbol then
      addProp (t, p, "")
    end if
  end repeat
  return t
end

-- LIST CHECK FUNCTIONS

on checkForList v, s
  if listP(v) then
    if ilk(v) = #proplist then
      t = pList_join (v,s)
      return t
    else if ilk(v) = #list then
      t = list_join (v,s)
      return t
    end if
  else
    t = v
    return t
  end if
  
end

on propCheckMyValueForType t
  if ilk(t) = #proplist then
    return t
  else if ilk(t) = #string then
    n = [:]
    setaProp (n, symbol(t), "")
    return n
  else if ilk(t) = #symbol then
    n = [:]
    setaProp (n, t, "")
    return n
  else
    alert   "Wrong Data Type"
    abort
  end if
end

on checkPropListForType t
  if ilk(t) = #proplist then
    return
  else
    alert   "Property List Expected"
    abort
  end if
end

on checkLinearListForType t
  if ilk(t) = #list then
    return
  else
    alert   "Linear List Expected"
    abort
  end if
end


-- STRING FUNCTIONS
on substr s, st, l
   st = st + 1
   if voidP(l) then
     e = s.length
   else
     e = l + (st - 1)
   end if
   ns = char st to e of s
   return ns
end

on substring  s, st, e
   if voidP(e) or (e > s.length) then
     e = s.length
   end if
   ns = char st to e of s
   return ns
end

on string_split s, d  
  itemCount = s.item.count
  put itemCount
  set the itemDelimiter to d
  myList = []
  repeat with i = 1 to itemCount
    list_push( myList,s.item[i] )
    put s.item[i]
  end repeat
  the itemDelimiter to ","
  return myList
end


on toUpperCase s
  lower = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  upper = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  ns = ""
  slength = s.length
  repeat with i = 1 to slength
    newChar = ""
    repeat with j = 1 to lower.count
      if s.char[i] = lower[j] then
        ns = ns & upper[j]
        newChar = upper[j]  
        exit repeat
      end if
    end repeat
    if newChar = "" then ns = ns & s.char[i]
  end repeat
  return ns
  
end

on toLowerCase s
  lower = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
  upper = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
  ns = ""
  slength = s.length
  repeat with i = 1 to slength
    newChar = ""
    repeat with j = 1 to upper.count
      if s.char[i] = upper[j] then
        ns = ns & lower[j]
        newChar = lower[j]  
        exit repeat
      end if
    end repeat
    if newChar = "" then ns = ns & s.char[i]
  end repeat
  return ns
end




 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail