Access an array attribute?

   3815   4   1
User Avatar
Member
81 posts
Joined: Aug. 2006
Offline
I have an attribute that is an array of ints, it works fine in the attribute wrangle that i defined it in. The array also shows up just fine in the spreadsheet.

I have attached a test scene, I define the attribute as an int array, am able to set its values and read them just fine. then when i try to access the attributes later i get no love.


first wrangle:
i[]@MyArray = {0,0,0,0};

@MyArray[0] = 2;
@MyArray[1] = 4;
@MyArray[2] = 6;
@MyArray[3] = 8;

printf("first Wrangle: %g\n", @MyArray[1]);

second wrangle:
printf("Second Wrangle: %g\n", @MyArray[1]);
and it blows up.

What am i doing wrong here? this seems like it should be straight forward…

Thanks in advance.
Edited by asmischney - Jan. 22, 2018 22:14:08

Attachments:
issue_arrayint.hip (73.7 KB)

User Avatar
Member
2038 posts
Joined: Sept. 2015
Offline
This works if you put it in your second wrangle:


i[]@MyArray = attrib(geoself(), "point", "MyArray", 0);
printf("first Wrangle: %g\n", @MyArray[1]);
User Avatar
Member
81 posts
Joined: Aug. 2006
Offline
BabaJ
This works if you put it in your second wrangle:


i[]@MyArray = attrib(geoself(), "point", "MyArray", 0);
printf("first Wrangle: %g\n", @MyArray[1]);

I just noticed that my code got mangled in my post, i will fix that.

thanks much for the reply, it appears that the second wrangle is stomping on the attribute made in the first, it copies the first points attribute to all of the other points

first wrangle:


second wrangle:


I changed the original wrangle to pu the point number in the first index of the array:
i[]@MyArray = {0,0,0,0};

@MyArray[0] = @ptnum;
@MyArray[1] = 4;
@MyArray[2] = 6;
@MyArray[3] = 8;

printf("first Wrangle: %g\n", @MyArray[1]);
[/quote]

Attachments:
2018-01-22 21_08_43-RE_GLDrawableWrapperWindow.png (27.0 KB)
2018-01-22 21_09_04-RE_GLDrawableWrapperWindow.png (28.5 KB)

User Avatar
Member
7759 posts
Joined: Sept. 2011
Offline
asmischney
thanks much for the reply, it appears that the second wrangle is stomping on the attribute made in the first, it copies the first points attribute to all of the other points

that's because that's what the code means:

i[]@MyArray = attrib(geoself(), "point", "MyArray", 0);

get the point attribute “MyArray” from point 0, and store in “MyArray”

your original post looked to merely be attempting to print the value of MyArray's second element:

printf("Second Wrangle: %g\n", @MyArray[1]);

This won't work because the binding ‘@’ will only do float, or predefined (Cd,P,N,id,etc) types. You need to specify the type for non-predefined attribute names.

printf("Second Wrangle: %d\n", i[]@MyArray[1]);
should print as expected. ( a bunch of 4's )
User Avatar
Member
81 posts
Joined: Aug. 2006
Offline
ah thank you, i knew i was getting tripped up in something head slapping.
that works, thanks much for the help! Hopefully i can contribute someday, still so much to learn!
  • Quick Links