Sie sind nicht angemeldet.

1

Montag, 11. Juli 2022, 17:23

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:

Quellcode

1
<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

2

Montag, 11. Juli 2022, 17:32

Sry but I can't find out how to format the code to multiple lines *sad*

3

Montag, 11. Juli 2022, 18:31

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

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<action name="customscenes" autorun="preinit">
	if(selectview,
		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);
				scene.removearrayitem(get(scene[get(i)].name));
				dec(i);
			,
				trace('keepScene ', scene[get(i)].name);
			);
		);
	,
		trace('no view selected, show all');
	);
</action>

Dieser Beitrag wurde bereits 5 mal editiert, zuletzt von »indexofrefraction« (11. Juli 2022, 21:11)


4

Dienstag, 12. Juli 2022, 22:45

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())...

Tuur

Erleuchteter

Beiträge: 3 839

Wohnort: Netherlands

Beruf: Krpano custom coding / Virtual Tours / Photography / Musician / Recording engineer

  • Nachricht senden

5

Mittwoch, 13. Juli 2022, 13:10

Hi,
this should works nice as well

Quellcode

1
2
3
4
5
6
7
8
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*