creating and storing multidimensional arrays

Ken Ray kray at sonsothunder.com
Wed Jan 7 00:32:43 EST 2009


> If I have created what I think is a multidimensional array using the
> code snippet below:
> 
> where say "index" = 23
> 
> put "fred" into wArray1[index]["theword"]  -- The word in question
> put 4 into  wArray1[index]["wlength"]    -- its length
> put 6 into  wArray1[index]["theline"]  -- the line containing the word
> put 24 into  wArray1[index]["theoffset"]  -- the character position
> word starts
> put "T1.2"  into wArray1[index]["theRef"]  --its reference
> 
> Is this a multidimensional array?

Yes it is - once you use more than one set of bracketed keys, you're into
multiple dimensions.
 
> If it is I am thus thinking "in effect" that wArray1[23]= "fred" 4 6
> 24 "T1.2"

Well, actually wArray[23] contains an *array* that has the "theword",
"wlength", "theline", "theoffset" and "theRef" keys in it.

For example:

  put wArray[23] into tArray
  put tArray["theword"]
  --> "fred"

  put tArray["wlength"]
  --> 4

  (etc.)

> If it is, how can I store this array in a custom property?
> 
> Will a line such as "set the customProperties["cpWordarray"] of this
> stack to wArray1" store the whole array?

Yes, but you can't use multiple dimensions with custom property set access
directly. That is, if you try to do:

  put the cpWordArray["23"]["theword"] of this stack

you'll get an error since although custom properties can contain arrays,
they can't be addressed with multiple dimensions. So you needto do it in
multiple steps:

  put the cpWordArray["23"] into tArray
  put tArray["theword"]
  --> "fred"


HTH,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list