scene.removearrayitem removing scenes randomly

  • Hi there

    I have a vtour where I have a bit more than ten panos. With the url params it should be possible to adress one pano and remove all the other panos. If no param is given, all panos remain in the tour.

    I used simmilar code before but with different filtering and it worked as expected. Now with this project i don't have any logic in the pano naming so to get rid of the unwanted panos i tried to get all panos and remove then by index.

    I got it to work partially, but instead of only one pano remains, there are about 5 remaining and the rest is deleted. I used trace to compare names etc. and I can't find the issue there.

    Here is my action:

    Code
    <action name="customscenes" autorun="preinit">	if(selectview !== null,	txtadd(scn, 'scene_', get(selectview));tolower(scn);		for(set(i,0), i LT scene.count, inc(i),				if(scene[get(i)].name !== scn,					trace('removeScene ', scene[get(i)].name);					set(scene[get(i)].name, null);				scene.removearrayitem(get(scene[get(i)].name));				,				trace('keepScene ', scene[get(i)].name);			);		);		,		trace('no view selected, show all');	);</action>

    Any hint why the panos get removed randomly?
    Thanks
    Sven

  • Hi Sven,

    just put the code in code tags (black # icon)

    i think this is unneeded, problematic and should get removed : set(scene[get(i)].name, null);
    but the main issue is that you must decrease i after removing a scene,
    because the same index will have the next scene then. otherwise you're skipping a scene.

    best, index

  • Piece of advice for all languages, be it krpano, javascript, python, php, etc...:When removing things from an array, you should loop the array reversewise (with dec() instead of inc())...

  • Hi,
    this should works nice as well

    Code
    for(sub(i,scene.count,1), i GE 0, dec(i),
          if(scene[get(i)].name !== scn,
              trace('removeScene ', scene[get(i)].name);
              scene.removearrayitem(get(scene[get(i)].name));
          ,
              trace('keepScene ', scene[get(i)].name);
          );
    );

    (untested)

    Tuur *thumbsup*

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!