array mystery

Ken Ray kray at sonsothunder.com
Thu May 3 15:10:20 EDT 2012


On May 3, 2012, at 12:47 PM, Peter M. Brigham, MD wrote:

> I have a customprop, CYPdata, that is an array, each element of which is an array itself. I am scraping the data to build CYPdata from an HTML page on the web, and filling it via script by parsing the HTML. There is an odd bug that I'm trying to get to the bottom of, and something strange is happening when I do the following in a test button:
> 
> on mouseUp
>   put the CYPdata of this stack into CYParray
>   put CYParray["fluvoxamine"] into aFLV
>   put CYParray["doxepin"] into aDOX
>   put aFLV is an array into testFLV
>   put aDOX is an array into testDOX
>   breakpoint
> end mouseUp
> 
> In the debugger variable pane at the breakpoint, expanding the array CYParray shows the keys, which are a whole list of drugs (as it should be), and each key/drug is indeed indicated as containing an array (with the little gray expansion triangle at the left). If I examine CYParray["fluvoxamine"] by clicking the expansion triangle, it shows the elements of that array, as expected. Same for CYParray["doxepin"]. The correct data is there in both cases. However, the aDOX variable does not display as an array (no expansion triangle) and testDOX = false, whereas aFLV is indeed an array, as displayed in the debugger and confirmed by testFLV = true.
> 
> What could be going on here? As it happens, the "doxepin" case is handled differently from the "fluvoxamine" case when I parse the HTML in loading the array, since they appear in slightly different contexts, so that must be the source of the difference, but how can the debugger show the "doxepin" array keys properly but somehow CYParray["doxepin"] not an array? Any ideas?

Peter, instead of trying to store multidimensional arrays "raw" in the custom property; can you use arrayEncode/arrayDecode? I think it might help eliminate issues; so assuming you parse the HTML and you have the data in a multidimensional array variable "CYParray", instead of doing:

  set the CYPdata of this stack to CYParray

do

  set the CYPdata of this stack to arrayEncode(CYParray)

… and then when you're ready to read it:

on mouseUp
  put arrayDecode(the CYPdata of this stack) into CYParray  -- changed line
  put CYParray["fluvoxamine"] into aFLV
  put CYParray["doxepin"] into aDOX
  put aFLV is an array into testFLV
  put aDOX is an array into testDOX
  breakpoint
end mouseUp

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