Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llGetPrimitive & llSetPrimitive

Brian Quinn
It.....
Join date: 9 May 2005
Posts: 31
04-27-2006 08:48
Ok, I am lost on this one. I understand that the llgetprim will return a "list" variable, but I cannot fathom what a "list" variable is and how I can intercept it, manipulate one value, and put the it back as a llsetprim vector. Basically, I just want to change one axis of the size of a prim when I click on it, probably in a for/next loop to give it some realistic motion appearance. I know llgetprimitive([prim_size]) will give me a list (I tried assigning that to a vector, nope that would be cheating apparently), so I am getting a list obviously when I click on the prim. I just have no idea where that list is going, how to capture it, and how to get it in a format I can manupulate.

Sorry for being clueless, but I am trying my best with the wiki and language guide to figure this out, and I am drawing a complete blank.
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
04-27-2006 09:07
If you just want to change the size (scale), you might be better off to use llGetScale and llSetScale. Then you don't have to try to get the vector out of the list or put it back. It should be much simpler and easier to understand. I've done the same sort of thing changing the scale of a prim in one direction, so if you need more help, just holler.

Baron Hauptmann
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-27-2006 10:41
From: Brian Quinn
Ok, I am lost on this one. I understand that the llgetprim will return a "list" variable, but I cannot fathom what a "list" variable is and how I can intercept it, manipulate one value, and put the it back as a llsetprim vector.

CODE
list l = llGetPrimitiveParams([LIST_FLEXIBLE]);// Get the list
vector force = llList2Vector(l, 6);// Extract an element from it.
force = frob(force);// Modify that element.
l = llListReplaceList(l,[force],6,6);// Put that element back.
llSetPrimitiveParams([LIST_FLEXIBLE] + l);// And... put the list.
Brian Quinn
It.....
Join date: 9 May 2005
Posts: 31
04-27-2006 11:40
I can't seem to get past the part of modify the vector, I just want to increment or decrement the z element, and it keeps telling me it's a type mismatch

list LIST_FLEXIBLE;

default
{
touch_start(integer total_number)
{
list l = llGetPrimitiveParams([LIST_FLEXIBLE]); // Get the list
vector size = llList2Vector(l, 9); // Extract an element from it.
size.z += <0,0,1>; // Modify that element, add one to z
l = llListReplaceList(l,[size],9,9); // Put that element back.
llSetPrimitiveParams([LIST_FLEXIBLE] + l); // And... put the list.
}
}
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-27-2006 12:32
From: Brian Quinn
I can't seem to get past the part of modify the vector, I just want to increment or decrement the z element, and it keeps telling me it's a type mismatch
That's not the only problem.

You need to use the list parameters that you're interested in. PRIM_FLEXIBLE (whoops, not LIST_FLEXIBLE, my bad) isn't one of them, unless you're doing this on the Preview grid. Look at llGetPrimitiveParams in the Wiki to find the one you want. If you're looking at PRIM_SIZE, you don't even need to rebuild the list. But... anyway...
CODE
list l = llGetPrimitiveParams([LIST_FLEXIBLE]);
//This is an error because you defined the (non-existent) parameter LIST_FLEXIBLE
//as a list, not an integer.
vector size = llList2Vector(l, 9); // Extract an element from it.
//Looks like you're using the PRIM_TYPE list and assuming the type it is.
size.z += <0,0,1>; // Modify that element, add one to z
//Either "size += <0,0,1>;" or "size.z += 1;".
l = llListReplaceList(l,[size],9,9); // Put that element back.
llSetPrimitiveParams([LIST_FLEXIBLE] + l); // And... put the list.


OK, using a real parameter list (in a stupid script):
CODE
list l = llGetPrimitiveParams([PRIM_TEXTURE,0]);
string name = llList2String(l, 0); // get an element
if(name == "5748decc-f629-461c-9a36-a35a221fe21f") // if it's blank we won't see it spin
{
name = llGetInventoryName(INVENTORY_TEXTURE, 0); // look for something
if(name == "") // nothing to replace it with.
name = "89556747-24cb-43ed-920b-47caed15465f"; //Use plywood
l = llListReplaceList(l,[name],0,0);// Put it back
}
float angle = llList2Float(l, 3); // get another element
angle += PI/6; // rotate it
l = llListReplaceList(l,[angle],3,3); // put it back
llSetPrimitiveParams([PRIM_TEXTURE]+l); // And set!
Brian Quinn
It.....
Join date: 9 May 2005
Posts: 31
04-27-2006 14:07
ok, neither the script you wrote, nor the one I wrote work. Yours gives this error: llSetPrimitiveParams error running rule #1 (PRIM_TEXTURE): arg #1 (face number) integer expected but key given, mine gives this error: llSetPrimitiveParams error running rule #2: unknown rule. This must be a lot tougher than it looks.

my current code is:
default
{
touch_start(integer total_number)
{
list l = llGetPrimitiveParams([PRIM_SIZE,3]); // Get the list
vector size = llList2Vector(l, 3); //Get an element
size.z += 1; // Modify that element, add one to z
l = llListReplaceList(l,[size],3,3); // Put that element back.
llSetPrimitiveParams([PRIM_SIZE] + l); // And... put the list.
}
}
which compiles just fine, but the running rules #1 and #2 don't appear to be in the wiki. I have assumed no variables types here, a list is a list, a vector is a vector. On a lighter note, the vector addition does work now, at least I think it does, as I know of know way to "say" a variable so I can debug this.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
04-27-2006 20:36
A few things wrong there. One, llGetPrimitiveParams() with PRIM_SIZE doesn't take any arguments other than PRIM_SIZE... you were adding another element, the number 3. Second, the list returned by the PRIM_SIZE request contains only one element, a vector representing the size of the object; your llList2Vector() command was referencing a non-existant fourth element of a 1-element list. And finally, with llListReplaceList, again, you were referencing the non-existant fourth element of a 1-element list.

I think where you might've gotten confused is that a vector value, while it has three components, is still just one vector value, and comprises only one element in a list.

Regarding lists, bear in mind that they begin numbering their elements at 0. So the first element is number 0, the second is number 1, etc.

This is the corrected version of your code, it's tested and working. :)

CODE
default
{
touch_start(integer total_number)
{
list l = llGetPrimitiveParams( [ PRIM_SIZE ] ) ; // Get the list

vector size = llList2Vector( l, 0 ); //Get an element

size.z += 1; // Modify that element, add one to z

l = llListReplaceList(l,[size],0,0); // Put that element back.

llSetPrimitiveParams([PRIM_SIZE] + l); // And... put the list.
}
}
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
04-27-2006 21:38
I wouldn't bother with PRIM_SIZE, i'd use llGetScale and llSetScale, just to avoid the hasle of dealing with the list.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Brian Quinn
It.....
Join date: 9 May 2005
Posts: 31
04-28-2006 02:08
Yep, that was the trick. I thought that the three elements of a vector would be three elements in the list. Thanks for helping me with that. I didn't use scale, as there was no way to just scale the prim in one direction, and I actually put the size changes in a loop with small increments, to simulate movement. This works good for me, even though it was a tough thing to figure out. Thanks for all your help.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-28-2006 08:44
From: Brian Quinn
ok, neither the script you wrote, nor the one I wrote work. Yours gives this error:
It's not tested, just deskchecked.
From: someone
llSetPrimitiveParams error running rule #1 (PRIM_TEXTURE): arg #1 (face number) integer expected but key given
Change the argument to [PRIM_TEXTURE]+0+l.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-28-2006 08:48
From: Brian Quinn
I didn't use scale, as there was no way to just scale the prim in one direction,
Erm... there's no way to just scale the prim in one direction with llSetPrimitiveParams, except the way you're doing it... reading, modifying, and writing. The same code using llSetScale would be...
CODE

default
{
touch_start(integer total_number)
{
vector size = llGetScale() ; // Get the vector
size.z += 1; // Modify that vector, add one to z
llSetScale(size); // And... put the vector back.
}
}
Which is why I was using PRIM_TEXTURE, because there's more of a reason to use llSetPrimitiveParams there, since I'm modifying two things at once.