2 dimensional Arrays

Dave dave at looktowindward.com
Wed Mar 14 07:13:09 EDT 2007


Hi,

The problem is that "arrays" in RunRev are not "arrays" in the same  
sense as in languages like C/C++ or Pascal etc. They are really look  
up tables. In RunRev instead of passing an index (or indexes) to  
retrieve the data for an entry you pass a key. You can fake the way  
Arrays work in languages like C/C++ etc, by passing key values such  
as "1,5", but this is actually passing a three character key of "1"  
"," "2".

I've found that if you are using the key section in a non-trivial way  
(like in the 2D array example) it's better to use a function that  
returns your munged key for you, e.g. something like this:

function Get2DArrayKey theIndex1,theIndex2

return theIndex1 & "," & theIndex2
end

and to use:

put "xxxx" into my2DArray[Get2DArrayKey(1,5) ]

or

put  my2DArray[Get2DArrayKey(1,5)] into myValue


If you *ALWAYS* use this function, you will always get consistent  
keys, otherwise you may have the problem you described where it's  
starts to get confusing because of extra quote characters, etc.

Hope this Helps
Dave


On 14 Mar 2007, at 08:33, Otto Hansen wrote:

> Thanks for that, the site made rev's arrays a little more  
> understandable.
>
> the method you sent me didn't seem to work but I managed to hack  
> together some code that works:
> put character 2 to the length of leftVar - 1 of leftVar into L
> put character 2 to the length of rightVar - 1 of rightVar into R
> answer myArray[L,R]
>
> This just strips away the quotation marks from leftVar and rightVar  
> which after seeing that I site I realized to be the problem
>
> Thanks,
> Otto
>
>
> Henk van der Velden wrote:
>> Hi Otto,
>>
>> Rev doesn't support 2 dimensional arrays, so you have to kind of  
>> fake them. That can be done by naming the keys the way you do. But  
>> if you want to get the value of a specific  key, you should use:
>> myArray["x" & comma & "y"]
>> instead of
>> myArray["x","y"]
>>
>> Hope this helps.
>>
>> You can also take a look at
>> http://www.sonsothunder.com/devres/revolution/tips/arry001.htm
>>
>> Kind regards,
>>
>> Henk
>> --------------------------
>> Henk v.d. Velden
>> iGlow Media
>> Magda Janssenslaan 36
>> 3584 GR  UTRECHT
>> Netherlands
>>
>> 0031 (0)6 16 024 337
>> www.iglow-media.nl
>>
>>
>>> I have a two dimensional array in my program and I am having some  
>>> trouble
>>> getting values to come out of it.
>>>
>>> The array is keyed in both dimentions by entries such as  
>>> "s1","s1" "s1","s2"
>>> etc. (the quotes are included in the key for various reasons but  
>>> they could
>>> potentially be removed)
>>>
>>> the values in the array are either empty or 1
>>>
>>> if I call for a value using something like:
>>> answer myArray["s1","s2"]
>>> I will get the value returned to me but if I try to use variables  
>>> it doesnt
>>> work right.
>>> If I have a variable leftVar that contains "s1" and rightVar that  
>>> contains
>>> "s2" (both with quotes) and I say
>>> answer myArray[leftVar,rightVar]
>>> I get returned an empty message.
>>>
>>> I dont seem to have this problem when calling a single dimension  
>>> array, only
>>> in my 2-dimension one.
>>>
>>
>>
>>
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list