Sie sind nicht angemeldet.

1

Dienstag, 16. April 2013, 16:31

set (and get) array elements

Hi to all

I'm trying to set two arrays, that they're going to be read next.

Quellcode

1
2
3
4
5
6
7
8
9
10
for(set(i,0), i LT hotspot.count, inc(i),
		
			add(risulta, hotspot[get(i)].ath, 10);
			set(listR[get(i)],get(risulta));
   		
			set(listName[get(i)], get(hotspot[get(i)].name));
//to test trace the hotspot array and new array created -> ok
			trace(hotspot[get(i)].name, " - ", listName[get(i)], " - ",listR[get(i)]);
	
	);


but, trying to read the new array it's seem that the overall array is only the last one set eg:

Quellcode

1
2
3
4
5
6
7
trace(listName[0])
trace(listName[1])
trace(listName[2])
...
trace(listName[N]) 

--> they're the same, ie the last value set


Perhaps I'm not able to manage properly the arrays... *cry*

Any kind of help... *g*

Regards...
zeno

2

Mittwoch, 17. April 2013, 14:26

Hi,

the krpano arrays are always 'arrays of objects' - where each array item is always a special object which has name and index properties - 'arrays of values' are not possible.

That means if you want to set some array item content, you need to set that to a property,
e.g.
set(listName[get(i)].hs, get(hotspot[get(i)].name));
...
trace(listName[0].hs);
trace(listName[1].hs);


For more details about krpano arrays, please also see here:
http://krpano.com/docu/plugininterface/#array

Best regards,
Klaus

3

Mittwoch, 17. April 2013, 19:37

solved

Hi Klaus

thanks for answer.
while trying to solve other item... I've "discovered" the logical flow of array of objects.

Now other new problems occour *confused* (ie: loadpano "echoes" of previous pano actions, variables and so on )

but for this kind of trouble new post.

thanks.
zeno

Anoril

Schüler

Beiträge: 69

Wohnort: Paris, France

Beruf: Game Developer and Photographer

  • Nachricht senden

4

Freitag, 25. Januar 2019, 12:17

Hi !
I'm experiencing a destabilizing behaviour with arrays.
I want a global array to store data. In a high-level action, I ask for array creation as documented:

Quellcode

1
def(miaou, array);

Then I start using it:

Quellcode

1
set( miaou[0].stuff, "meow" );

But this tells me :

Zitat

WARNING: set miaou[0].stuff=meow - miaou is not an array!
... WHY ?!?
If I don't use DEF(), it works... ^_^ But I don't really like using data I don't initialize...
Pleaaaase, help ! :D
« Quidquid latine dictum sit, altum sonatur »
Pentax stuff.

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Anoril« (25. Januar 2019, 12:36)


5

Mittwoch, 30. Januar 2019, 14:38

Hi,

by using:

Quellcode

1
def(miaou, array);
you're defining a special 'value-array':
https://krpano.com/docu/actions/#valuearrays

Such arrays can directly contain values, not objects like the normal arrays.
Add/set a value this way:

Quellcode

1
2
3
def(miaou, array);
set(miaou[0], "meow");
debugvar(miaou);


For 'normal' arrays just use the set, then the array will be created automatically:

Quellcode

1
2
set(miaou[0].stuff, "meow" );
debugvar(miaou);


See also here for more:
https://krpano.com/docu/actions/#arrays

But if you want to explicitly create/define the array the createarray function can be used:
https://krpano.com/docu/plugininterface/#createarray
E.g.

Quellcode

1
2
3
createarray(miaou);
set(miaou[0].stuff, "meow" );
debugvar(miaou);


Best regards,
Klaus

Ähnliche Themen