Difference between revisions of "LlGetEnergy"

From Second Life Wiki
Jump to navigation Jump to search
(fix counters)
(fix owner text and collision event)
Line 11: Line 11:
// This script tests the energy use of most of the physics functions
// This script tests the energy use of most of the physics functions
// 18 March 2008 by Karzita Zabaleta
// 18 March 2008 by Karzita Zabaleta
 
vector homePos;
vector homePos;
integer timerCount = 0;
integer timerCount = 0;
integer testCount = 0;  
integer testCount = 0;  
 
// move more than 10m
// move more than 10m
moveTo(vector origin, vector destination) {
moveTo(vector origin, vector destination) {
Line 28: Line 28:
     llSetPrimitiveParams(params);
     llSetPrimitiveParams(params);
}
}
 
returnHome()
returnHome()
{
{
    llSetTimerEvent(0);
     llSetStatus(STATUS_PHYSICS, FALSE);
     llSetStatus(STATUS_PHYSICS, FALSE);
     llSleep(0.2);
     llSleep(0.2);
     moveTo(llGetPos(),homePos);
     moveTo(llGetPos(),homePos);
    llSetTimerEvent(0);
     llSetRot(ZERO_ROTATION);
     llSetRot(ZERO_ROTATION);
}
}
 
default
default
{
{
Line 54: Line 54:
         llSetStatus(STATUS_PHYSICS,TRUE);
         llSetStatus(STATUS_PHYSICS,TRUE);
         llSetTimerEvent(1.0);
         llSetTimerEvent(1.0);
       
         vector impulse = <0,0,5>*llGetMass();
         vector impulse = <0,0,5>*llGetMass();
         if (testCount == 0) {
         if (testCount == 0) {
Line 107: Line 107:
         }
         }
         timerCount = 0;
         timerCount = 0;
         llOwnerSay((string)timerCount+". energy   :"+(string)llGetEnergy());
         llOwnerSay((string)timerCount+". Energy:   "+(string)llGetEnergy());
         testCount++;
         testCount++;
     }
     }
     timer() {
     timer() {
         timerCount++;
         timerCount++;
         llOwnerSay((string)timerCount+". energy   :"+(string)llGetEnergy());
         llOwnerSay((string)timerCount+". Energy:   "+(string)llGetEnergy());
         if (timerCount>=10) { // just in case floating
         if (timerCount>=10) { // just in case floating
             returnHome();
             returnHome();
Line 118: Line 118:
     }
     }
     collision(integer n) {
     collision(integer n) {
         llOwnerSay((string)timerCount+". energy   :"+(string)llGetEnergy());
        timerCount = 0;
         llOwnerSay((string)timerCount+". Energy:   "+(string)llGetEnergy()+" (collision)");
         returnHome();
         returnHome();
     }
     }
}
}
</lsl>
</lsl>
|helpers
|helpers

Revision as of 05:08, 7 October 2009

Summary

Function: float llGetEnergy( );
0.0 Forced Delay
10.0 Energy

Returns a float that is how much energy is in the object as a percentage of maximum

Examples

<lsl> // This script tests the energy use of most of the physics functions // 18 March 2008 by Karzita Zabaleta

vector homePos; integer timerCount = 0; integer testCount = 0;

// move more than 10m moveTo(vector origin, vector destination) {

   float dist = llVecDist(origin, destination);
   integer passes = llCeil( llLog(dist/10.0) / llLog(2.0) );
   integer i;
   list params = [PRIM_POSITION, destination];
   for (i=0; i<passes; i++) {
       params = (params=[]) + params + params;
   }
   // actually move the prim, now
   llSetPrimitiveParams(params);

}

returnHome() {

   llSetTimerEvent(0);
   llSetStatus(STATUS_PHYSICS, FALSE);
   llSleep(0.2);
   moveTo(llGetPos(),homePos);
   llSetRot(ZERO_ROTATION);

}

default {

   state_entry() {
       homePos = llGetPos();
       llOwnerSay("Mass is "+(string)llGetMass());
   }
   on_rez(integer _n) {
       llResetScript();
   }
   touch_start(integer n) {
       do {
         llSleep(0.5);
       } while (llGetEnergy() < 0.998);
       llSetPos( llGetPos()+<0,0,5>);
       llSetStatus(STATUS_PHYSICS,TRUE);
       llSetTimerEvent(1.0);

       vector impulse = <0,0,5>*llGetMass();
       if (testCount == 0) {
           llOwnerSay("ApplyImpulse");
           llApplyImpulse( impulse, TRUE ); 
       } else if (testCount == 1) {
           llOwnerSay("ApplyRotImpulse");
           llApplyRotationalImpulse( impulse, TRUE);
       } else if (testCount == 2) {
           llOwnerSay("PushObject");
           llPushObject(llGetKey(), impulse, ZERO_VECTOR, TRUE); 
       } else if (testCount == 3) {
           llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
           llOwnerSay("Force");
           llSetForce( impulse, TRUE ); 
       } else if (testCount == 4) {
           llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
           llOwnerSay("Torque");
           llSetTorque( impulse, TRUE ); 
       } else if (testCount == 5) {
           llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
           llOwnerSay("Force and Torque");
           llSetForceAndTorque( impulse, impulse, TRUE ); 
       } else if (testCount == 6) {
           llSetForceAndTorque( ZERO_VECTOR, ZERO_VECTOR, TRUE ); 
           llOwnerSay("MoveToTarget");
           llMoveToTarget( impulse, 0.4 ); 
       } else if (testCount == 7) {
           llStopMoveToTarget ( ); 
           llOwnerSay("RotLookAt");
           llRotLookAt( llEuler2Rot(impulse*DEG_TO_RAD), 0.4, 0.4 ); 
       } else if (testCount == 8) {
           llStopLookAt ( ); 
           llOwnerSay("LookAt");
           llLookAt( impulse, 0.4, 0.4 ); 
       } else if (testCount == 9) {
           llStopLookAt ( ); 
           llOwnerSay("Hover Height");
           llSetHoverHeight( 5.0, TRUE, 0.5);
       } else if (testCount == 10) {
           llSetHoverHeight( 0, TRUE, 0.5);
           llOwnerSay("Ground Repel");
           llGroundRepel( 5, TRUE, 0.5);
       } else if (testCount == 11) {
           llGroundRepel( 0, TRUE, 0.5);
           llOwnerSay("Buoyancy");
           llSetBuoyancy( 0.997 );
       } else {
           llSetBuoyancy( 0.0 );
           llOwnerSay("Done");
           testCount=(-1);
       }
       timerCount = 0;
       llOwnerSay((string)timerCount+". Energy:    "+(string)llGetEnergy());
       testCount++;
   }
   timer() {
       timerCount++;
       llOwnerSay((string)timerCount+". Energy:    "+(string)llGetEnergy());
       if (timerCount>=10) { // just in case floating
           returnHome();
       }
   }
   collision(integer n) {
       timerCount = 0;
       llOwnerSay((string)timerCount+". Energy:    "+(string)llGetEnergy()+" (collision)");
       returnHome();
   }

}

</lsl>

Deep Notes

Signature

function float llGetEnergy();