what does myarray ["this stuff"] stands for ?

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

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

what does myarray ["this stuff"] stands for ?

Post by liveme » Wed Feb 24, 2021 9:40 pm

Hi,
Can any guruz let me know what the braket content text stands for ?
using array method : put "abc" into anArray["whatever"]

one can rename it as:
...into arrayone["insideX"]
..into arrayzilion["insideY"]

Question : if arrayone is the "Name of the array" what does "insideX" stands for ?
- why does it even needs to be named if arrayone is already the array own name?
:? 8)
Thanks :idea:

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: what does myarray ["this stuff"] stands for ?

Post by Klaus » Wed Feb 24, 2021 9:56 pm

That are the KEYS of the array!
Or better the NAMES of the keys of the array.
...
put "Some string..." into arrayone["insideX"]
...
answer arrayone["insideX"]
## -> Some string...

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

Re: what does myarray ["this stuff"] stands for ?

Post by bogs » Wed Feb 24, 2021 10:07 pm

If you haven't already seen it, might I suggest some simple arrays?
Image

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: what does myarray ["this stuff"] stands for ?

Post by stam » Thu Feb 25, 2021 1:23 am

put simply arrays in LiveCode can be considered multidimensional but really i liken them to a dictionary of dictionaries (or hash tables).

As an example, here's a simple numeric array (in LC these are 1-based rather than 0-based as with almost all other languages)
simple numeric array.jpg
In the simple example, arrayName[3] = Stephen

however arrays don't have to have numerical keys and can have a multitude of keys making them an extremely flexible way to store data, kinda like a spread sheet:
complex array.jpg
here
- arrayName["user3"]["name"] = stephen
- arrayName["user3"]["age"] = 17
even better, keys can contain whole other arrays and once you get the hang of it, it's a superb vehicle for managing complex data structures -- pretty much like jSON but better ;)

hope that makes sense...

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: what does myarray ["this stuff"] stands for ?

Post by liveme » Thu Feb 25, 2021 1:50 am

Klaus wrote:
Wed Feb 24, 2021 9:56 pm
Or better the NAMES of the keys of the array.
...Okay, I kind of understand the naming need of the array group of keys inside....(though, if one can already name the array "arrayfruit" ...I dont really see the need of re-specifying ["fruits"] inside...but, ok, that was planned this way for some reasons most likely.

If I could NOT to rename the array arrayfruit and arrayvegie ..I could understand why one needs to rename the "goup of keys inside".
It just looks a bit redundant (to me) but I can live with it,
I do not see in what case one would find helpfull to have 2 names "pointing" to the same content at the end versus using just the distinct name for the array only:
any examples ?
:?: :?

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: what does myarray ["this stuff"] stands for ?

Post by stam » Thu Feb 25, 2021 1:56 am

liveme wrote:
Thu Feb 25, 2021 1:50 am
2 names "pointing" to the same content at the end.
erm no, that's not it at all.... hopefully my previous post makes sense.
You don't always need arrays however - if you only have list of names, then just create a return-based list instead.

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am

Re: what does myarray ["this stuff"] stands for ?

Post by Davidv » Thu Feb 25, 2021 6:39 am

Perhaps it will be clearer if I point out, purely for clarity, that "arrayname" is a placeholder for the name you choose for your array, while the bit in square brackets is the key to an element within your array. Incidentally, the arrays do not "start from 1" because the keys are purely textual -- "0" is just another textual key, like "-24" or "frog".

Let us say you call your array Arvast. We will put three elements into it then show the keys and one of the elements:

Code: Select all

ON mouseUp
   put "Arthur" into Arvast[0]
   put "Martha" into Arvast[-24]
   put "Flat" into Arvast[frog]
   put the keys of Arvast & cr & Arvast[frog]
END mouseUp
However, one should quote the keys within the array, not what I did above. Look what happens when "frog" remains a literal string which could also be a variable:

Code: Select all

ON mouseUp
   put "Arthur" into Arvast[0]
   put "Martha" into Arvast[-24]
   put "Flat" into Arvast[frog]
   put the keys of Arvast & cr & Arvast[frog]
   wait 2 secs
   put "-24" into frog
   put Arvast[frog]
END mouseUp
See what happened there when you run the second code? Play around for a while, recognising that you have three things, the array name (just another variable you create), the key, which is textual and in square brackets (and could be a variable), and the stored data item in each element.

Does that clarify naming for you? Are you familiar with arrays in other languages?

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: what does myarray ["this stuff"] stands for ?

Post by liveme » Thu Feb 25, 2021 7:49 am

Does that clarify naming for you?
mmm.. I guess I need a bit more time to get use to see an expression inside those brackets, I've run both your working codes stan but it just add more to my confusion
Are you familiar with arrays in other languages?
at some point... indeed I first learned about array starting coding practice with Dart.
which uses LIST SET and MAP for 3 "types" of arrays...

Code: Select all

List >	list MyList = [1,3,2];
Set>        list MySet = {"a","b","c"};
Map	>     Map MyMap = {"a":1,"b":2};
..with which - of the little practice I got - the only time when you'd find a "string" within brackets is only when you want to refer to "one of the value from your array".
I.e
myArray.add("Teo");
....to "Add" new value "Teo" to an array named myArray.

So I guess thats part of what my tiny brain keeps fighting against in LC : using of a the reference to a value in the bracket that - as I undertstand till now - is NOT one of the key or value from an array, but just a name of "a group of values"...or I still don't get it right ?!!! :lol: :lol:
[Lost case coder]

glenn9
Posts: 234
Joined: Wed Jan 15, 2020 10:45 pm

Re: what does myarray ["this stuff"] stands for ?

Post by glenn9 » Thu Feb 25, 2021 9:54 am

I found this lesson really helpful in learning about arrays https://livecode.byu.edu/arrays/introToArrays.php and I often go back to it to refresh understanding etc...

Davidv
Posts: 77
Joined: Sun Apr 09, 2006 1:51 am

Re: what does myarray ["this stuff"] stands for ?

Post by Davidv » Thu Feb 25, 2021 10:26 am

liveme wrote:
Thu Feb 25, 2021 7:49 am
... the reference to a value in the bracket that - as I undertstand till now - is NOT one of the key or value from an array, but just a name of "a group of values"...or I still don't get it right ?!!! :lol: :lol:
Read the lessons suggested by glenn9.

The value inside brackets is indeed the key to an element in the array, not some 'group of values'. I demonstrated this in my first example code (not to mention the second when you get to the point being made in that part).

I'm not stan.

cheers
David

stam
Posts: 3072
Joined: Sun Jun 04, 2006 9:39 pm

Re: what does myarray ["this stuff"] stands for ?

Post by stam » Thu Feb 25, 2021 12:36 pm

Davidv wrote:
Thu Feb 25, 2021 10:26 am
I'm not stan.
Neither am I :)

Stam

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: what does myarray ["this stuff"] stands for ?

Post by liveme » Thu Feb 25, 2021 12:49 pm

i'm not stan either !
:P
so indeed if this value is one of the keys...
the array can be written ( similar to Dart )
- put "apple" into myarray[] (with no names inside brakets !)
:!:

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

Re: what does myarray ["this stuff"] stands for ?

Post by bogs » Thu Feb 25, 2021 1:00 pm

liveme wrote:
Thu Feb 25, 2021 12:49 pm
so indeed if this value is one of the keys...
the array can be written ( similar to Dart )
- put "apple" into myarray[] (with no names inside brakets !)
Image

Not quite, but you *could* do something like this -
Image

Ps - did you even look at simple arrays? If you did look at it, what part of it wasn't clear to you? If I find that out, I may be able to clarify the video for the next person ;)
Image

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm

Re: what does myarray ["this stuff"] stands for ?

Post by liveme » Thu Feb 25, 2021 7:42 pm

thanks bogs...
ok, so there is a dif syntax between my conception of defining arrays in dart and the one in LC. Doesnt surprise me just confuse me a lil bit.
- so ..put apple into myarray[] / not exist in LC.

Well no, I havent look into links that do not refer to some "LC website" lessons or tuto yet :
1 thing is ..if its not an LC made syntax, its likely to add to my confusion of how an LC code can be written like.
2nd I 've been trying to focus on the PDF dictionaries and guide but one is really very technical and doesnt offer simple complete code samples
and the other sometimes skip that part that one wanted to see how it is written.

The other site I m using is https://livecode fandom com/wiki/RevOpenDatabase which seems to offer plenty of clear code sample, with explainings and "stick" to the LC language.

Scripted shared stack, I usualy downlaoded many, and go through reading their code and try to find anything usefull to me.

so, really youtube is usually my last choice, reason : it takes for ever to guess if they will treat your wanted search, it's not the most fun way to read code, etc....beside, you need to find the video somehow in itself...

*I guess I'm laking a simple cook book with damn super simple examples of each LC function/feature with code and explaining.

Thanks for the tKey tips...will surely rise mode questions in my head :shock: now, put hopefully that change after viewing your youtube link !
:D :D :D

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: what does myarray ["this stuff"] stands for ?

Post by Klaus » Thu Feb 25, 2021 7:47 pm

Another good resource, not especially for arrays, but al basic cobncepts in LC, are the "Scripting Conference" stacks:
http://www.hyperactivesw.com/revscriptc ... ences.html

Post Reply