Array not finding key

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Array not finding key

Post by ittarter » Thu Jul 12, 2018 3:19 pm

Hello all,

I've scratched my head for a week on this. Any ideas on what might be going wrong or how I can test it?

Livecode 9.0, Windows 10.

I'm using a multidimensional array tArray and I'm having problems with a single element. Basically I'm trying to create tab delimited data out of certain values for each element in the array, for example
for ID 0001
tArray["ID"]["ID"] = 0001
tArray["ID"]["title"] = words
tArray["ID"]["EN Description"] = fox,box,talks,locks
for ID 0002
tArray["ID"]["ID"] = 0002
tArray["ID"]["title"] = numbers
tArray["ID"]["EN Description"] = 343,632,735,121


For some reason, unlike all the other elements in the array, one element "EN Description" always yields empty. Of course, I assumed that I had spelled something incorrectly, but I've checked a thousand times and there's nothing inconsistent. I've even renamed the variable and the problem remains.

Code: Select all

repeat for each element y in tArray
      put the keys of y into tKeys --yields multiple lines including "EN Description"
      if y["EN Description"] is empty then --always triggered, even though I can plainly see a string of text in my dubug window
         put y["ID"] && y["title"] & return after tData --ID and title values are found, no problem
      else
         put y["ID"] && y["title"] & ":" && y["EN Description"] & return after tData
      end if
   end repeat
I've checked this every way I can, going back to the source of the array, which works fine to create tab delimited data using a test button and field. It's just in THIS iteration where I'm having trouble.

Thanks,

Ivan

Klaus
Posts: 10289
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Array not finding key

Post by Klaus » Thu Jul 12, 2018 3:37 pm

Just made a quick test with this script:

Code: Select all

on mouseUp 
   repeat with i = 1 to 3
      put i into tArray[i]["ID"]
      put i & "fox,box,talks,locks" into tArray[i]["EN Description"]
   end repeat
   
   repeat for each element y in tArray
      put the keys of y into tKeys --yields multiple lines including "EN Description"
      put y["EN Description"] into tCurrentElement
      
      if y["EN Description"] is empty then
         put y["ID"] && y["title"] & return after tData --ID and title values are found, no problem
      else
         put y["ID"] && y["title"] & ":" && y["EN Description"] & return after tData
      end if
   end repeat
end mouseUp
and it worked as axspected, three lines in tData and NO empty y["EN Description"]!
Did I miss anything?

ittarter
Posts: 151
Joined: Sat Jun 13, 2015 2:13 pm

Re: Array not finding key

Post by ittarter » Thu Jul 12, 2018 3:43 pm

Thanks for the response, Klaus.

After some more head-scratching, there is apparently some invisible non-space character at the end of my key name IN the array.

They sure are sneaky. Perhaps it's because I ctrl-C-ed the data from an Open Office table...

Klaus
Posts: 10289
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Array not finding key

Post by Klaus » Thu Jul 12, 2018 4:00 pm

Perhaps it's because I ctrl-C-ed the data from an Open Office table...
Ah, yes, that is possible, good catch!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”