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.

Umalo

Professional

  • "Umalo" started this thread

Posts: 1,051

Location: Osijek, Croatia, EU

  • Send private message

1

Sunday, February 24th 2013, 11:19pm

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

Beginner

Posts: 40

Location: Latvia

Occupation: Kosmodroms | Digital Creative Studio - programmer, designer

  • Send private message

2

Monday, February 25th 2013, 3:48pm

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:

Source code

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

Umalo

Professional

  • "Umalo" started this thread

Posts: 1,051

Location: Osijek, Croatia, EU

  • Send private message

3

Monday, February 25th 2013, 4:49pm

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

Beginner

Posts: 40

Location: Latvia

Occupation: Kosmodroms | Digital Creative Studio - programmer, designer

  • Send private message

4

Tuesday, February 26th 2013, 3:37pm

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

Umalo

Professional

  • "Umalo" started this thread

Posts: 1,051

Location: Osijek, Croatia, EU

  • Send private message

5

Tuesday, February 26th 2013, 10:46pm

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

Thursday, February 28th 2013, 2:18pm

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:

Source code

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


The correct setting code would be:

Source code

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


Or to test it better try:

Source code

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


Best regards,
Klaus

Umalo

Professional

  • "Umalo" started this thread

Posts: 1,051

Location: Osijek, Croatia, EU

  • Send private message

7

Saturday, March 2nd 2013, 10:39pm

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:

Source code

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:

Source code

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?