You are not logged in.

San7

Intermediate

  • "San7" started this thread

Posts: 309

Occupation: coding in krpano

  • Send private message

1

Friday, April 3rd 2020, 9:39am

Syntax Question

Hello, syntax question. How to find out the number of elements

<test a1="1" a2="2" a3="3" />

How to find out the number of "a№"?
How to get the value "a№" by its number?
How to get the name "a№" by its number?
*question*

2

Friday, April 3rd 2020, 12:31pm

Source code

1
2
3
4
5
6
// normal
trace(test.a1);

// dynamic
set(num,1);
trace(calc("test.a"+num));


but you probably mean something else...
getting the attribute name would be doable by javascript only.
but that its getting a bit complicated...

what do you want to do?

Tuur

Sage

Posts: 3,325

Location: Netherlands

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

  • Send private message

3

Friday, April 3rd 2020, 1:19pm

Hi,

i was also trying to get this info some time ago..
https://krpano.com/forum/wbb/index.php?p…&threadID=17357

i think San7 wants to know the amount of attributes which is 3 in the example.

a1
a2
a3

and then call them for index number, name and value.
I might be wrong though..

Tuur *thumbsup*
http://www.virtualtuur.com
Skype:studiotuur

San7

Intermediate

  • "San7" started this thread

Posts: 309

Occupation: coding in krpano

  • Send private message

4

Friday, April 3rd 2020, 2:20pm

Yes for example

<test a1="tt" a2="yy" a3="uu" />


trace (test [item] .count) --> 3 (3 elements)
trace (test [2]) --> yy(the second element contains yy)

trace (test [2].name) --> a2 (name of the second element)


But this is the wrong syntax, these are my fantasies *smile*



This post has been edited 1 times, last edit by "San7" (Apr 3rd 2020, 3:02pm)


5

Thursday, April 9th 2020, 12:26pm

Hi,

please see the thread Tuur linked, there you see the answer:
https://krpano.com/forum/wbb/index.php?p…81170#post81170

Best regards,
Klaus

San7

Intermediate

  • "San7" started this thread

Posts: 309

Occupation: coding in krpano

  • Send private message

6

Thursday, April 9th 2020, 4:28pm

Klaus, thanks for the helpful example!
This works when there is a name:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<test  name="test1"   a1="tt" a2="yy" a3="uu" />

<action autorun="onstart" type="Javascript"><![CDATA[
    var layer = krpano.get("test[test1]");
    var attributes = layer.getattributes();
    for (var i=0; i < attributes.length; i++)
    {
        var attrib = attributes[i];
        var value = layer[attrib];
	krpano.set("value", value);
	krpano.set("attrib", attrib);
	krpano.call("trace(attrib,=,value)");
    }
]]></action>


Can this be done if there is no name?

Source code

1
<test   a1="tt" a2="yy" a3="uu" />
*confused*

7

Thursday, April 9th 2020, 5:23pm

Source code

1
2
3
4
5
6
7
8
9
<test a1="tt" a2="yy" a3="uu" />

<action autorun="onstart" type="Javascript"><![CDATA[
	var el = krpano.get("test");
	var att = el.getattributes();
	for (var i=0; i < att.length; i++)  {
		krpano.trace(1, att[i] + ' = ' + el[att[i]]);
	}
]]></action>

San7

Intermediate

  • "San7" started this thread

Posts: 309

Occupation: coding in krpano

  • Send private message

8

Thursday, April 9th 2020, 5:25pm

It works! Thanks! *thumbsup* *thumbsup* *thumbsup*