Multidimensional Arrays? Please Help with Lesson

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
ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Multidimensional Arrays? Please Help with Lesson

Post by ValiantCuriosity » Sat Mar 16, 2019 10:01 pm

Hello again fellow Adventurers,

I've been trying to get my head around custom properties (as in save the variables and reopen the stack to see the variables in a field--thank you @Jacque for mentioning this ability). That seems to be working. I'm still having brain fog over custom properties, but for now I'm happy. :D

I've been working with one dimensional arrays and, again, I think I'm understanding them. So there is more good news from your lost in the woods of LC newbie.

My greater issue is that, for my little test application, I need to use multidimensional arrays. However, when I try to recreate the lesson that is given on the LC site,http://lessons.livecode.com/m/4071/l/21 ... dable-form ,I am having no success. I've typed the code in many times. I've copied it in too. I figured that I was making a mistakes in the code. I've tried putting the function and other code within the lesson into the Handler on openCard and on preOpenCard as well as into a button on the card. Also tried the message box as indicated in the lesson. I simply can't get anything to run. I'm not understanding what is wrong. Is there a friendly wayfarer that can help me find the path in these woods again?

I call the function/handler (vocabulary is the hidden monster in the LC woods) using this bit of code from a button object. Apparently the code was left out of the original lesson and someone else caught it in the comments section.

Code: Select all

displayArrayData(tCustomerArrayData,".")
I did notice that the local variable was misnamed in the above answer. I believe the lesson example named the local array: local tCustomerDataArray. I changed it in my code, but that didn't work either.

When I run the code in the message box, I get nothing--and empty message box. Somehow, the data isn't getting read into the program.
Thanks again. I hope that your day is/was "most excellent".

-Rachel
May I never be cured of my curiosity! :D

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

Re: Multidimensional Arrays? Please Help with Lesson

Post by jacque » Sun Mar 17, 2019 6:25 pm

I haven't looked at the lesson, but arrays can't be displayed as text so you'll always get empty in the message box or anywhere else that expects a string. They need to be converted to text before you can see them. However, the debugger does this for you so you can see them in the variable watcher. So if you put a breakpoint somewhere in the display handler, execution will stop there and you'll see the values in the lower pane of the editor.

Make sure that script debugging is turned on in the Development menu or breakpoints won't work.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Multidimensional Arrays? Please Help with Lesson

Post by SparkOut » Sun Mar 17, 2019 6:39 pm

That lesson provides the displayArrayData function. So if you are going to use it from the message box, you will not be able just to call it like a command (or handler).

You need to use a command in the message box to call the function and do something with the value that it returns. In this case a simple "put" will do:

Code: Select all

put displayArrayData(tCustomerArrayData,".")
will get the return value from the function and output to the default-if-not-otherwise-specified-destination of the message box.

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Multidimensional Arrays? Please Help with Lesson

Post by SparkOut » Sun Mar 17, 2019 6:44 pm

That lesson provides the displayArrayData function. So if you are going to use it from the message box, you will not be able just to call it like a command (or handler).

You need to use a command in the message box to call the function and do something with the value that it returns. In this case a simple "put" will do:

Code: Select all

put displayArrayData(tCustomerArrayData,".")
will get the return value from the function and output to the default-if-not-otherwise-specified-destination of the message box. But you could

Code: Select all

put displayArrayData(tCustomerArrayData,".") into field "myDisplayFieldToShowTheResult"

ValiantCuriosity
Posts: 128
Joined: Thu Jun 30, 2016 3:08 am

Re: Multidimensional Arrays? Please Help with Lesson

Post by ValiantCuriosity » Mon Mar 18, 2019 2:12 am

Thank you @SparkOut. Your help set me on the right path. Finally got this to work. The error in the lesson didn't help, but it was also partly me just not understanding what was wrong.

For other beginners, this lesson helped me too. It deals with what @Jacque mentions in her reply.

Code: Select all

http://lessons.livecode.com/m/4071/l/7810-how-do-i-display-an-array-in-a-table-field
-Rachel
May I never be cured of my curiosity! :D

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Multidimensional Arrays? Please Help with Lesson

Post by mrcoollion » Mon Mar 18, 2019 8:09 pm

The easiest way to show the contents of an array I found is to put the Tree Widget in a card and fill it with the array data (tTestData) with the following one line of code.

Code: Select all

   set the arraydata of widget TreeView to tTestData

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

Re: Multidimensional Arrays? Please Help with Lesson

Post by bogs » Mon Mar 18, 2019 8:15 pm

Tough call between that, and just using the debugger. I think I actually prefer the debugger (and not just because I don't use later versions of Lc :wink: ), because I can expand the individual keys into separate fields and view all their contents, and leave the fields open to see any changes made.

It is pretty handy, and only costs setting a breakpoint in the code. One line? One word baby! :mrgreen:
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”