I have an object that can be rezzed in-world or worn. Depending on whether it's rezzed or worn it will resize to different sizes and enable/disable certain functions.
This has been working well for over a year until I started using the Emerald viewer a few weeks ago, now when I rezz or wear the object from inventory it sometimes detects the incorrect state with llGetAttached and does the wrong things!
If I reset the script after rezzing/attaching then it sorts itself out correctly so it seems the llGetAttached() called in the on_rez event is getting executed before the object has fully attached and giving false results sometimes with the emerald client.
I thought maybe I should use the attach() event to do the resize and the llRequestPermissions call inside the running state instead of inside the on_rez, and that would be fine when the object is attached, but how would I then handle when the object is rezzed as the attach() event won't be triggered?
So... does anybody have any suggestions on how to best handle this situation to ensure the object will resize/take controls correctly when rezzed or attached from inventory?
Note: My script is rather long, so I have extracted the bits that are relevent to this discussion below rather than confusing things with lines and lines of script.;
CODE
default
{
state_entry()
{
if (llToLower(llGetObjectDesc()) =="debug"){
DEBUGMODE = TRUE;;
}
if (llGetAttached()>0){
if (llToLower(llGetObjectDesc()) =="autoresize"){ // if (iAutoResize ==TRUE){
llSetPrimitiveParams([PRIM_SIZE,<.08, .13, .04>, PRIM_ROTATION,llEuler2Rot(<0,0,120>*DEG_TO_RAD)]);
}
iHUDAttached = TRUE;
}
else {
iHUDAttached=FALSE;
if (llToLower(llGetObjectDesc()) =="autoresize"){ // if (iAutoResize ==TRUE){
llSetPrimitiveParams([PRIM_SIZE,<.5, .5, .75>,PRIM_ROTATION,llEuler2Rot(<0,0,0>*DEG_TO_RAD)]);
}
}
//
// This section loads settings from a notecard and validates them before setting state to "running"
//
state Running;
}
}
}
state Running
{
state_entry()
{
if (DEBUGMODE == TRUE) llOwnerSay("state running _ state_entry");
integer iTimer;
if (iHUDAttached == TRUE){ //If Hud is Attached to avatar
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
}
llListen(iChan,"",llGetOwner(),""); // Listen on user configurable channel for voice commands
llOwnerSay("Listening on channel "+(string)iChan+" use '/" + (string)iChan +" help' for instructions and commands.");
llOwnerSay("Free Memory: " +(string)llGetFreeMemory());
llSetTimerEvent(iTimer);
}
run_time_permissions(integer perms)
{
llTakeControls(CONTROL_LBUTTON, 0, 1);
}
}
on_rez(integer iRez)
{
llSetTimerEvent(0.0);
if (DEBUGMODE == TRUE) llOwnerSay("state running _ on_rez");
if (llGetAttached()>0){
if (llToLower(llGetObjectDesc()) =="autoresize"){ // if (iAutoResize ==TRUE){
llSetPrimitiveParams([PRIM_SIZE,<.08, .13, .04>, PRIM_ROTATION,llEuler2Rot(<0,0,120>*DEG_TO_RAD)]);
}
llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
iHUDAttached = TRUE;
}
else {
iHUDAttached=FALSE;
if (llToLower(llGetObjectDesc()) =="autoresize"){ // if (iAutoResize == TRUE){
llSetPrimitiveParams([PRIM_SIZE,<.5, .5, .75>,PRIM_ROTATION,llEuler2Rot(<0,0,0>*DEG_TO_RAD)]);
}
}
if (iDisplayText == TRUE){
llSetText(sHeader1 + "\n" + sHeader2 + "\n" + "Loading...",vTextColor,fAlpha);
}
llOwnerSay("Loading..");
integer iLength = llGetListLength(lAvi_status);
//
// Do stuff in here before enabling timer
//
llSetTimerEvent(0.5);
}
many thanks
Bones