You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, May 2nd 2017, 12:16pm

How to get the Array/List count?

Hi

I have some problems with an actual array. I do not get the count of it.
Here is the code of the array and the function to read it.
I do get the product and color value out of it.

What is wrong there?

Source code

1
2
3
<array name="cart99">	<item name="i0" product="product1" color="red" url="123"/>	<item name="i1" product="product2" color="blue"/><item name="i2" product="product3" color="green"/>	</array>
	<action name="test">	trace(cart99.count);
		trace(array[cart99].item[i1].product);trace(array[cart99].item[0].color);	</action>


PS: How can i format the code properly?

Thanks
Sven

2

Tuesday, May 2nd 2017, 4:17pm

Hi Sven,


Your array should be:
<array name="cart99">
<sub name="item0" product="product1" color="red" url="123" />
<sub name="item1" product="product2" color="blue" url="231" />
<sub name="item2" product="product3" color="green" url="321" />
</myarray >

array count of sub-items:
trace(array[cart99].sub.count);

get a value of array:
trace(array[cart99].sub[item0].product);

With a quick for() Action you can get all the infos of your array:

for(set(i, 0), i LE array[cart99].sub.count, inc(i),
txtadd(myTargetItem, 'item', get(i) );
trace(array[cart99].sub[get(myTargetItem)].product );
trace(array[cart99].sub[get(myTargetItem)].color );
trace(array[cart99].sub[get(myTargetItem)].url );
);

NOT tested, but should work...

Best,
Steve

This post has been edited 1 times, last edit by "svb" (May 2nd 2017, 4:48pm)


spacerywirtualne

Professional

Posts: 860

Location: Poland, Europe

Occupation: krpano developer : virtual tours

  • Send private message

3

Thursday, May 4th 2017, 11:19am

Or simply:


Source code

1
2
3
4
5
6
for(set(i,0),i LT array[cart99].sub.count,inc(i),  
  copy(n, array[cart99].sub[get(i)]);
  trace('product: ',get(n.product));  
  trace('color: ',get(n.color));  
  trace('url: ',get(n.url));
)



*thumbup*

Best regards
Piotr
You own online, cloud tool for creating virtual tours - www.cms4vr.com

facebook page :: facebook group :: youtube

cms4vr team *thumbsup*

4

Friday, May 5th 2017, 2:06am

Hi Piotr

thanks for that. I didn't know that you also have to tell krpano the sub element.