Page 1 of 1

multidimensional array issue

Posted: Sun Feb 26, 2012 1:18 am
by josemv
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

Re: multidimensional array issue

Posted: Sun Feb 26, 2012 1:29 am
by sturgis
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.

Re: multidimensional array issue

Posted: Sun Feb 26, 2012 10:16 am
by josemv
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

Re: multidimensional array issue

Posted: Sun Feb 26, 2012 3:41 pm
by sturgis
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.