set (and get) array elements

  • Hi to all

    I'm trying to set two arrays, that they're going to be read next.

    Code
    for(set(i,0), i LT hotspot.count, inc(i),
    		
    			add(risulta, hotspot[get(i)].ath, 10);
    			set(listR[get(i)],get(risulta));
       		
    			set(listName[get(i)], get(hotspot[get(i)].name));
    //to test trace the hotspot array and new array created -> ok
    			trace(hotspot[get(i)].name, " - ", listName[get(i)], " - ",listR[get(i)]);
    	
    	);

    but, trying to read the new array it's seem that the overall array is only the last one set eg:

    Code
    trace(listName[0])
    trace(listName[1])
    trace(listName[2])
    ...
    trace(listName[N]) 
    
    
    --> they're the same, ie the last value set

    Perhaps I'm not able to manage properly the arrays... *cry*

    Any kind of help... *g*

    Regards...
    zeno

  • Hi,

    the krpano arrays are always 'arrays of objects' - where each array item is always a special object which has name and index properties - 'arrays of values' are not possible.

    That means if you want to set some array item content, you need to set that to a property,
    e.g.
    set(listName[get(i)].hs, get(hotspot[get(i)].name));
    ...
    trace(listName[0].hs);
    trace(listName[1].hs);

    For more details about krpano arrays, please also see here:
    https://krpano.com/docu/plugininterface/#array

    Best regards,
    Klaus

  • Hi Klaus

    thanks for answer.
    while trying to solve other item... I've "discovered" the logical flow of array of objects.

    Now other new problems occour *confused* (ie: loadpano "echoes" of previous pano actions, variables and so on )

    but for this kind of trouble new post.

    thanks.
    zeno

  • Hi !
    I'm experiencing a destabilizing behaviour with arrays.
    I want a global array to store data. In a high-level action, I ask for array creation as documented:

    Code
    def(miaou, array);


    Then I start using it:

    Code
    set( miaou[0].stuff, "meow" );


    But this tells me :

    Quote

    WARNING: set miaou[0].stuff=meow - miaou is not an array!

    ... WHY ?!?
    If I don't use DEF(), it works... ^_^ But I don't really like using data I don't initialize...
    Pleaaaase, help ! :D

    « Quidquid latine dictum sit, altum sonatur »
    Pentax stuff.

    Edited once, last by Anoril (January 25, 2019 at 12:36 PM).

  • Hi,

    by using:

    Code
    def(miaou, array);

    you're defining a special 'value-array':
    https://krpano.com/docu/actions/#valuearrays

    Such arrays can directly contain values, not objects like the normal arrays.
    Add/set a value this way:

    Code
    def(miaou, array);
    set(miaou[0], "meow");
    debugvar(miaou);

    For 'normal' arrays just use the set, then the array will be created automatically:

    Code
    set(miaou[0].stuff, "meow" );
    debugvar(miaou);

    See also here for more:
    https://krpano.com/docu/actions/#arrays

    But if you want to explicitly create/define the array the createarray function can be used:
    https://krpano.com/docu/plugininterface/#createarray
    E.g.

    Code
    createarray(miaou);
    set(miaou[0].stuff, "meow" );
    debugvar(miaou);

    Best regards,
    Klaus

Participate now!

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