Sie sind nicht angemeldet.

Lieber Besucher, herzlich willkommen bei: krpano.com Forum. Falls dies Ihr erster Besuch auf dieser Seite ist, lesen Sie sich bitte die Hilfe durch. Dort wird Ihnen die Bedienung dieser Seite näher erläutert. Darüber hinaus sollten Sie sich registrieren, um alle Funktionen dieser Seite nutzen zu können. Benutzen Sie das Registrierungsformular, um sich zu registrieren oder informieren Sie sich ausführlich über den Registrierungsvorgang. Falls Sie sich bereits zu einem früheren Zeitpunkt registriert haben, können Sie sich hier anmelden.

1

Sonntag, 24. Februar 2013, 23:19

two dimensional array

Hi
How to set two dimensional array? Have played but not sure how to define it.
e.g.
<array name="1" >
<array name="1" value="11" />
<array name="2" value="12" />
<array name="3" value="13" />
</array >
<array name="2" >
<array name="1" value="21" />
<array name="2" value="22" />
<array name="3" value="23" />
</array >
<array name="3" >
<array name="1" value="31" />
<array name="2" value="32" />
<array name="3" value="33" />
</array >

When I want to get value I use: trace(array[2].array[3].value);

What if I want to use it as simple two dimensional array like:
trace(array[2].array[3]);
or
trace(array[2][3]);

How to define it?
Initialization with for loop works fine:

for(set(i,1), i LE 3, inc(i),
for(set(j,1), j LE 3, inc(j),
set(array[get(i)][get(j)],999);
);
);

but how to define this type of array with no .value
Any thoughts? *huh*

kosmodroms

Anfänger

Beiträge: 40

Wohnort: Latvia

Beruf: Kosmodroms | Digital Creative Studio - programmer, designer

  • Nachricht senden

2

Montag, 25. Februar 2013, 15:48

something like this works for me but i didn't figure out how to define nested <array> nodes with values. if values are set dynamically it works fine:

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
		trace(get(array[1][1])); 
		trace(get(array[1][2])); 
		trace(get(array[1][3])); 
		trace(get(array[2][1])); 
		trace(get(array[2][2])); 
		trace(get(array[2][3])); 

		for(set(i,1), i LE 2, inc(i),
			for(set(j,1), j LE 3, inc(j),
				set(array[get(i)][get(j)], random);
			);
		);

		trace(get(array[1][1])); 
		trace(get(array[1][2])); 
		trace(get(array[1][3])); 
		trace(get(array[2][1])); 
		trace(get(array[2][2])); 
		trace(get(array[2][3]));
Edgars
Kosmodroms | Digital Creative Studio
www.kosmodroms.lv

3

Montag, 25. Februar 2013, 16:49

Yap, *thumbup* that is why asked if someone got idea how to define that type of array. I have fix set of numbers that I need later and would be nice to understand how to easy define it, other than using .value or .something....

kosmodroms

Anfänger

Beiträge: 40

Wohnort: Latvia

Beruf: Kosmodroms | Digital Creative Studio - programmer, designer

  • Nachricht senden

4

Dienstag, 26. Februar 2013, 15:37

I don't think it's possible. Maybe Klaus knows how to do it. I guess I would then just define values on startup() using set(array[#][#], #);
Edgars
Kosmodroms | Digital Creative Studio
www.kosmodroms.lv

5

Dienstag, 26. Februar 2013, 22:46

I see you also think in the same way. For start I need to fill it with 96*12 entries. It would mean +1k set commands ;( I search for some easier way to fill two dimensional array.
Seams that we wait for Klaus to give some proposal here. He always pull out some rabbit from the hat.

6

Donnerstag, 28. Februar 2013, 14:18

Hi,
What if I want to use it as simple two dimensional array like:
trace(array[2].array[3]);
or
trace(array[2][3]);
there are no 'value-arrays' in krpano, each array in krpano is always an array of objects.

That means your code will not work - it only shows random output values in the trace test, because you are setting the array itself to the random action:

Quellcode

1
set(array[get(i)][get(j)], random);


The correct setting code would be:

Quellcode

1
set(array[get(i)][get(j)], get(random));


Or to test it better try:

Quellcode

1
txtadd(array[get(i)][get(j)], 'item_',get(i),'_',get(j));


Best regards,
Klaus

7

Samstag, 2. März 2013, 22:39

Thanks for replay. Maybe I am missing the point of arrays (objects storage vs values) but we should have some possibility to store predefined data in some later easy accessible way. What would be easiest way to fill matrix of 96*12 with values which I need later for some calculations. It is also to be taken in consideration what I need to access this values knowing column and row where the data is stored.
At lest something like:

Quellcode

1
<data name="1" k_1="12" k_2="14" k_3="18" k_4="2" k_5="58" k_6="65" k_7="0" k_8="0" k_9="0" k_10="0" k_11="0" k_12="0" />


would be ok but don't know how to access it via numerical definiton of position:

Quellcode

1
2
3
4
5
set(i,1);set(j,2);<!-- Ok, this is clear way to access it--> trace(data[get(i)].k_2); 

<!-- Have stored approprate subnode name in num_kat varialble, Any ways to access it this way--> 
set(num_kat,'k_');txtadd(num_kat,get(j));trace('subnode:',num_kat); <!-- This way this doesn't work -->
trace(data[get(i)].num_kat);


Or any other ways to store and get data knowing i and j


It is clear if I would't have huge number of data, I would do it manually with set(.... ,value) but as it is so many definitions needed I search for some ways that I am missing here. Most probably not knowing about. I am still persistent to do it directly in Krpano code, but also learned/experienced that Math is very slow, maybe I will pass data to js and do the math there and return the result. What do you suggest?