Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation scripting problem

Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
01-20-2007 11:13
I'm trying to make a chari cushion into a 'pose ball' but in order to get the guests to sit correctly, I need to rotate them because the cushion is rotated. I have been looking around for how to do it and found the following example code:

vector eul = <0, 0, 45>; // 45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot( eul ); // convert to quaternion
llSetRot( quat ); // rotate the object

I've seen this in multiple locations, including the Wiki, and yet when I try to use it, I get syntax errors... The first of which is at 'eul *=' (40, 4) : Error : Syntax error.

I tried doing some tinkering but I'm getting other syntax errors between function names and open perens, etc. Any ideas what's going on?

Thanks!
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
01-20-2007 11:21
The code you posted compiles fine for me.

Can you post your code here?
Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
01-20-2007 11:30
Bear in mind I'm just getting used to LSL, so right now I'm in the stage of using scripts I'm finding, and then modifying it to suit, while I get the hang of the new bells & whistles.

That being said, I'm currently experimenting with a pose ball script.. I've highlighted the scripting I've added with comments...

//*****************************************
//* Nyterave animation ball script! *
//* FREE TO USE V2.1 *
//* by Sitting Lightcloud *
//******************************************/

// * * * * * * * MODIFY BELOW * * * * * * *//


// position to sit on the ball e.g <0.0, 0.0, 0.43>
// sit 0.5 meter above the ball
vector POSITION=<0.0, 0.0, 1.0>;

// hovertext above ball. "" for none.
// add '\n ' at the end to move text up i.e.
// string HOVERTEXT="Sit Here\n ";
string HOVERTEXT="Sit Here";

// Pie Menu Sit Text. Will only work for the
// main prim but included it anyway. If no text
// is entered between "" it won't be used.
string SIT_TEXT="Have a Seat!";


// hovertext color 'r,g,b' e.g. "255,255,255" (white)
string HOVER_RGB="255,255,255";

// LISTEN sets if this ball should listen for voice commands
// or not. You only need to enable this for 1 ball if you
// link several balls to an object. (to reduce lagg).
// Change to TRUE to enable FALSE to disable.
integer LISTEN=FALSE;

// What channel to listen for hide/show on. If you want to
// listen to normal conversation (hide/show), set channel
// to 0 otherwise the command will be /channel hide, show
integer CHANNEL=8;

// HERE IS THE CODE I ADDED TO DO A QUATERNION CONVERSION //

// rotation of avatar //
vector eul = <0, 0, 45>; // 45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot( eul ); // convert to quaternion
llSetRot( quat ); // rotate the object

// END MY ADDED CODE //

// * * * * * * * STOP MODIFY * * * * * * * *//




set_text()
{
if (llStringLength(HOVERTEXT)>0)
{
rgb=llCSV2List(HOVER_RGB);
llSetText(HOVERTEXT,<llList2Float(rgb,0)*0.003921568627450980392156862745098,llList2Float(rgb,1)*0.003921568627450980392156862745098,llList2Float(rgb,2)*0.003921568627450980392156862745098>,1.0);

}
else
llSetText("",<0,0,0>,0.0);
}
start_listen()
{
llListenRemove(listener);
if (LISTEN==TRUE)
listener=llListen(CHANNEL,"","","";);
}
hide_me()
{
// don't hide since it's not a pose ball
llSetAlpha(1.0, ALL_SIDES);
llSetText("",<0,0,0>,0.0);
}
show_me()
{
llSetAlpha(1.0, ALL_SIDES);
set_text();
}
list rgb;
string animation;
integer listener;
default
{
state_entry()
{
if (llStringLength(SIT_TEXT)>0)
llSetSitText(SIT_TEXT);
llSitTarget(POSITION, ROTATION);
set_text();
start_listen();
}

on_rez(integer r)
{
start_listen();
}

listen(integer channel, string name, key id, string msg)
{
if (msg=="hide";)
{
hide_me();
llMessageLinked(LINK_SET,0,"hide", NULL_KEY);
}
else if (msg=="show";)
{
show_me();
llMessageLinked(LINK_SET,0,"show", NULL_KEY);
}
}

changed(integer change)
{
if (change & CHANGED_LINK)
{

if (llAvatarOnSitTarget() != NULL_KEY)
{
llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);
}
else
{
integer perm=llGetPermissions();
if ((perm & PERMISSION_TRIGGER_ANIMATION) && llStringLength(animation)>0)
llStopAnimation(animation);
llSetAlpha(1.0, ALL_SIDES);
set_text();
animation="";
}
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("sit";);
animation=llGetInventoryName(INVENTORY_ANIMATION,0);
llStartAnimation(animation);
llSetAlpha(1.0, ALL_SIDES);
llSetText("",<0,0,0>,0.0);
}
}

link_message(integer sender_num, integer num, string str, key id)
{
if (str=="hide";)
{
hide_me();
}
else if (str=="show";)
{
show_me();
}
}
}
Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
01-20-2007 11:38
Okay, I just found out where the syntax issue is coming from, Some of the code is in the wrong location within the script... So I guess now my question is why this section of code shouldn't be outside of the default state:

// rotation of avatar //
vector eul = <0, 0, 45>; // 45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot( eul ); // convert to quaternion
llSetRot( quat ); // rotate the object
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
01-20-2007 11:50
Code is either in functions or inside events. If you put code somewhere else, LSL has no idea when to actually 'run' it.

Btw, please surround posted code with the
CODE
 tags, to make it more readable.
_____________________
Barry Moody
Registered User
Join date: 17 Dec 2006
Posts: 24
01-20-2007 11:54
Sorry about the readability... I'll be sure to do that from now on. I am just going to start from scratch and hope for the best on this. Thanks for your help!
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
01-20-2007 12:09
You need to put your rotation code in the top of the state_entry event. And llSetRot will rotate the object, not the avatar, so you need to add your rotation to the sittarget:

CODE

state_entry()
{
// rotation of avatar //
vector eul = <0, 0, 45>; // 45 degrees around the z-axis, in Euler form
eul *= DEG_TO_RAD; //convert to radians
rotation quat = llEuler2Rot( eul ); // convert to quaternion

if (llStringLength(SIT_TEXT)>0)
llSetSitText(SIT_TEXT);
llSitTarget(POSITION, quat);
set_text();
start_listen();
}

_____________________