multidimensional array issue

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
josemv
Posts: 11
Joined: Mon Jan 05, 2009 4:51 pm

multidimensional array issue

Post by josemv » Sun Feb 26, 2012 1:18 am

Hello

after several hours trying to find what's wrong, have to ask what I must fix in this code:

Code: Select all

      put "at 1 " & regServers["net"]["server"] & " : " & domainExtension & cr after field "datafield"
      put "at 2 " & regServers[domainExtension]["server"] & cr & cr after field "datafield"
      put "at 3 " & regServers["net"]["server"] & " : " & domainExtension & cr & cr after field "datafield"
Produce this output:

Code: Select all

at 1 enom.com : net

at 2 

at 3 enom.com : net
Why array using key variable doesn't returns anything?

Thanks
Jose

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: multidimensional array issue

Post by sturgis » Sun Feb 26, 2012 1:29 am

Works fine for me, did you copy and paste the code? Can you paste in the whole script?

Not sure what it could be other than possibly a typo in the 'at 2' line, or if the lines are in different places maybe a scope issue with regards to the domainextension variable.

josemv
Posts: 11
Joined: Mon Jan 05, 2009 4:51 pm

Re: multidimensional array issue

Post by josemv » Sun Feb 26, 2012 10:16 am

Hi Sturgis,

the scope issue makes sense to me. Because I'm completelly new with LiveCode, probably am doing something wrong.

The code its only a test and it is a crazy mix of statement to check how some things work.

I have all code inside of a button objet script. I declared variables on the stack as global and they are not available at script button, then tried on the button itself and got some progress but not much as you can see.

LiveCode lack a good book, something that describes in a structured way all about the language. The book seems an IDE description and the Dicitonary helps when you know what to do. Add how special it is LiveCode and then have you have me going in circles :(

Thanks
Jose

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: multidimensional array issue

Post by sturgis » Sun Feb 26, 2012 3:41 pm

You have to declare globals everywhere they need to be used, so that might be part of the issue.

If you declare it only in the stack script, the global is seen only in the stack script and its handlers.

For your button script to use the same global you need to declare it there also at which point the same global value can be seen/used/changed in both scripts.

You might consider using a property instead. If you "set the myproperty of this stack to "whatever value" you can get to it from anywhere without re-declaring.

Also, for learning the language, the users guide isn't bad.

You can find links to the dictionary online, the users guide, and the tutorial lessons here. http://www.runrev.com/developers/documentation/

There is also some good stuff at http://livecode.byu.edu/ There are additional useful links at that location also.

For your array questions, the lessons site (sub link from the top link above) has some array specific lessons.

Also, this lesson http://lessons.runrev.com/s/lessons/m/4 ... -variables goes over alternatives to using globals and is a good read.

Then there is this http://www.fourthworld.com/embassy/arti ... _path.html by richard gaskin that is a really great read on message path mechanics.

Post Reply