Using a value as a key in array

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Using a value as a key in array

Post by FourthWorld » Wed Jan 08, 2020 11:24 pm

dunbarx wrote:
Wed Jan 08, 2020 10:58 pm
Jacque.

A fair point. And if one is careful, one can surely use numbers, even with field names.

But I would still do what we both have advised in the past, maybe something like “p1”?
Integer names for objects are problematic in some cases because LC allows us to refer to objects by ordinal number, creating an ambiguity about how the object is being addressed.

Array keys are always strings, even if characters in the string are numerals. We don't currently have indexed arrays in LC Script, only associative arrays, so there's no ambiguity in addressing them.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a value as a key in array

Post by jacque » Wed Jan 08, 2020 11:39 pm

What Richard said. In my case, using numeric references is the cleanest way to do it. There's no danger, numeric array keys are unique references.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Using a value as a key in array

Post by dunbarx » Thu Jan 09, 2020 12:12 am

You are both right.

I was being overly pedantic.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7237
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Using a value as a key in array

Post by jacque » Thu Jan 09, 2020 1:58 am

dunbarx wrote:
Thu Jan 09, 2020 12:12 am
I was being overly pedantic.
Oh, I don't know. Maybe just overly cautious. :-)
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”