Page 1 of 1

Maniascript array, how to get n:th element out ?

Posted: 10 May 2016, 20:23
by reaby
Problem:
I have array with strings as keys... how to access value by index number ?

problematic is when the records array has 500 or 1000 keys... foreach loop comes slow to find the keys (onMouseOver)

Re: Maniascript array, how to get n:th element out ?

Posted: 10 May 2016, 21:55
by maxi031
This is the way i would do it:

Code: Select all

declare Text[Integer] myArray = [0=>"value 0", 1=>"value 1", 2=>"value 2"];
than you should be able to access it with number:

Code: Select all

log(myArray[0]);
This should print: value 0;

Re: Maniascript array, how to get n:th element out ?

Posted: 12 May 2016, 13:12
by Eole
reaby wrote:Problem:
I have array with strings as keys... how to access value by index number ?
You can't. :(

A possible dirty and bug-prone solution if you don't have any alternative would be to the one suggested above by maxi031.

Code: Select all

declare FirstArray = [0 => "A", 1 => "B", 2 => "C"];
declare SecondArray = ["A" => "ZZZ", "B" => "YYY", "C" => "XXX"];
log(SecondArray[FirstArray[2]]); //< XXX

Re: Maniascript array, how to get n:th element out ?

Posted: 12 May 2016, 23:27
by reaby
Eole wrote: A possible dirty and bug-prone solution if you don't have any alternative would be to the one suggested above by maxi031.

Code: Select all

declare FirstArray = [0 => "A", 1 => "B", 2 => "C"];
declare SecondArray = ["A" => "ZZZ", "B" => "YYY", "C" => "XXX"];
log(SecondArray[FirstArray[2]]); //< XXX
This solves my problem totally, as i fear the foreach loop is way too slow.
I can update the first array with foreach easily, and then use the buffered value later.

Many many thanks,
Reaby