two dimensional array

  • Hi
    How to set two dimensional array? Have played but not sure how to define it.
    e.g.
    <array name="1" >
    <array name="1" value="11" />
    <array name="2" value="12" />
    <array name="3" value="13" />
    </array >
    <array name="2" >
    <array name="1" value="21" />
    <array name="2" value="22" />
    <array name="3" value="23" />
    </array >
    <array name="3" >
    <array name="1" value="31" />
    <array name="2" value="32" />
    <array name="3" value="33" />
    </array >

    When I want to get value I use: trace(array[2].array[3].value);

    What if I want to use it as simple two dimensional array like:
    trace(array[2].array[3]);
    or
    trace(array[2][3]);

    How to define it?
    Initialization with for loop works fine:

    for(set(i,1), i LE 3, inc(i),
    for(set(j,1), j LE 3, inc(j),
    set(array[get(i)][get(j)],999);
    );
    );

    but how to define this type of array with no .value
    Any thoughts? *huh*

  • something like this works for me but i didn't figure out how to define nested <array> nodes with values. if values are set dynamically it works fine:

  • I see you also think in the same way. For start I need to fill it with 96*12 entries. It would mean +1k set commands ;( I search for some easier way to fill two dimensional array.
    Seams that we wait for Klaus to give some proposal here. He always pull out some rabbit from the hat.

  • Hi,

    What if I want to use it as simple two dimensional array like:
    trace(array[2].array[3]);
    or
    trace(array[2][3]);

    there are no 'value-arrays' in krpano, each array in krpano is always an array of objects.

    That means your code will not work - it only shows random output values in the trace test, because you are setting the array itself to the random action:

    Code
    set(array[get(i)][get(j)], random);

    The correct setting code would be:

    Code
    set(array[get(i)][get(j)], get(random));

    Or to test it better try:

    Code
    txtadd(array[get(i)][get(j)], 'item_',get(i),'_',get(j));

    Best regards,
    Klaus

  • Thanks for replay. Maybe I am missing the point of arrays (objects storage vs values) but we should have some possibility to store predefined data in some later easy accessible way. What would be easiest way to fill matrix of 96*12 with values which I need later for some calculations. It is also to be taken in consideration what I need to access this values knowing column and row where the data is stored.
    At lest something like:

    Code
    <data name="1" k_1="12" k_2="14" k_3="18" k_4="2" k_5="58" k_6="65" k_7="0" k_8="0" k_9="0" k_10="0" k_11="0" k_12="0" />

    would be ok but don't know how to access it via numerical definiton of position:

    Code
    set(i,1);set(j,2);<!-- Ok, this is clear way to access it--> trace(data[get(i)].k_2); 
    
    
    <!-- Have stored approprate subnode name in num_kat varialble, Any ways to access it this way--> 
    set(num_kat,'k_');txtadd(num_kat,get(j));trace('subnode:',num_kat); <!-- This way this doesn't work -->
    trace(data[get(i)].num_kat);



    Or any other ways to store and get data knowing i and j


    It is clear if I would't have huge number of data, I would do it manually with set(.... ,value) but as it is so many definitions needed I search for some ways that I am missing here. Most probably not knowing about. I am still persistent to do it directly in Krpano code, but also learned/experienced that Math is very slow, maybe I will pass data to js and do the math there and return the result. What do you suggest?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!