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)
Maniascript array, how to get n:th element out ?
Moderator: English Moderator
Re: Maniascript array, how to get n:th element out ?
This is the way i would do it:
than you should be able to access it with number:
This should print: value 0;
Code: Select all
declare Text[Integer] myArray = [0=>"value 0", 1=>"value 1", 2=>"value 2"];
Code: Select all
log(myArray[0]);
My specs:
MOBO: MB AM3+ 970 Gigabyte GA-970A-DS3P
CPU: AM3+ AMD FX-8320E
GPU: Nvidia GeForce GTX750-Ti ASUS 2GB DDR5
RAM: DDR3 8GB 1866MHz Kingston HyperX
SSD: SATA3 120gb SanDisk
OS: Ubuntu 19.04
TY MICMO
MOBO: MB AM3+ 970 Gigabyte GA-970A-DS3P
CPU: AM3+ AMD FX-8320E
GPU: Nvidia GeForce GTX750-Ti ASUS 2GB DDR5
RAM: DDR3 8GB 1866MHz Kingston HyperX
SSD: SATA3 120gb SanDisk
OS: Ubuntu 19.04
TY MICMO
Re: Maniascript array, how to get n:th element out ?
You can't.reaby wrote:Problem:
I have array with strings as keys... how to access value by index number ?

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 ?
This solves my problem totally, as i fear the foreach loop is way too slow.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
I can update the first array with foreach easily, and then use the buffered value later.
Many many thanks,
Reaby
Who is online
Users browsing this forum: No registered users and 1 guest