Lists as in []

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
TooManyNotes
Posts: 10
Joined: Fri Nov 16, 2018 2:01 am

Lists as in []

Post by TooManyNotes » Fri Nov 16, 2018 2:57 pm

In Director 12, where I’m coming from, there is a construct called “lists,” and used to store data like so: [“A”, “B”, “C”] etc. To get at the data, one uses syntax like listName.getAt[1], etc. Is there such a thing in LC 9? If so, what is it called?
TIA

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

Re: Lists as in []

Post by dunbarx » Fri Nov 16, 2018 3:12 pm

Hi.

It sounds like you are describing an array variable. Arrays in LC are associative, and my attain any depth.

So you might, for a single level array:

Code: Select all

on mouseUp
   put "A" into listName["1"]
   put "B" into listName["2"]
   put "C" into listName["3"]
   
   answer listName["2"]
end mouseUp
Arrays are special variables, as opposed to "ordinary" variables.

Write back if you need more. You might read page 125 in the user guide.

Craig Newman

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

Re: Lists as in []

Post by Klaus » Fri Nov 16, 2018 3:27 pm

Yep, ARRAYS are one way to do it, but QUOTES are not neccessary for keys that are numbers.

Another way is to use ITEMS or LINES:

Code: Select all

...
put "A,B,C" into tItemList
put item 3 of tItemList
## -> C
...
Or lines:

Code: Select all

...
put "A" & CR & "B" & CR & "C" into tLineList
put line 2 of tLineList
## -> B
...
Or if your strings already contain commas, we can SET itemdelimiter, which defaults to COMMA, to whatever we need, even to more than 1 character!

Code: Select all

...
put "AyaddaByaddaC" into tYaddaList
set itemdel to "yadda"
put item 1 of tYaddaList
## -> A
...
Does not really make sense, but you get the picture :D


Best

Klaus

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

Re: Lists as in []

Post by dunbarx » Fri Nov 16, 2018 3:32 pm

What Klaus is referring to are known as "chunk" expressions, These should become second nature to you, since they provide intrinsic parsing of text down to the character level.

A chunk can take several forms, and just as importantly, there are several functions that access them directly.

Back to the user guide, page 416, at least in v.8x.

Craig

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Lists as in []

Post by cbarbal » Sat Nov 17, 2018 5:16 pm

Where can you get a PDF user guide? I have revision 19 (2010.11.09).

Regards,

Carles

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

Re: Lists as in []

Post by Klaus » Sat Nov 17, 2018 5:20 pm

Hi Carles,

the "User Guide" is part of every LC installation and you can access it in LC via menu -> Help -> User Guide


Best

Klaus

cbarbal
Posts: 114
Joined: Fri May 08, 2015 5:04 pm

Re: Lists as in []

Post by cbarbal » Sat Nov 17, 2018 5:36 pm

Hi Klaus,

Thanks for the information, every day you learn new things :D

Regards,

Carles

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Lists as in []

Post by bogs » Sat Nov 17, 2018 8:44 pm

This is one of the few times I actually recommend using either the dictionary to access the guides, or James Hale's excellent docset reader (on usershare/samples).
Dictionary_001.png
Guiding light eh?
I've actually chunked through the pdf (a few times) as I'm sure almost everyone else has. The dictionary has given a series of guides as a much more navigable document than the pdf itself.

When using the actual pdf guide, though, I tend to prefer to open that in Firefox, just for ease of use (like allowing autoscrolling, good search, etc.). Best of all, if you have FF open with the 'windows and tabs from last session' set, it will open the pdf to where you left off.
Open File_002.png
Ctrl + open in Firefox...
LiveCode User Guide.pdf - Mozilla Firefox_003.png
Pretty good cross platform pdf reader that remembers its place...
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”