LSL Status/Kan-ed10

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(New page: '''Code:''' vector startPosition; float groundLevel; default { state_entry() { llListen( 0, "", llGetOwner(), ""); startPosition = llGetPos(); grou...)
 
m (Robot: Cosmetic changes)
 
(6 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
__NOTOC__
 +
{{Quicklinks}}
 +
<br />
 +
 
'''Code:'''
 
'''Code:'''
  
 
  vector startPosition;
 
  vector startPosition;
 
  float groundLevel;
 
  float groundLevel;
+
 
 
  default
 
  default
 
  {
 
  {
Line 9: Line 13:
 
     {
 
     {
 
         llListen( 0, "", llGetOwner(), "");
 
         llListen( 0, "", llGetOwner(), "");
 
+
 
         startPosition = llGetPos();
 
         startPosition = llGetPos();
 
         groundLevel = llGround( startPosition );
 
         groundLevel = llGround( startPosition );
 
+
   
 
         llSay( 0, "Control this object with chat commands like:" );
 
         llSay( 0, "Control this object with chat commands like:" );
 
         llSay( 0, "'up' or 'down' followed by a distance." );
 
         llSay( 0, "'up' or 'down' followed by a distance." );
 
     }   
 
     }   
   
+
     
 
     listen( integer channel, string name, key id, string message )  
 
     listen( integer channel, string name, key id, string message )  
 
     {
 
     {
 
         // separate the input into blank-delmited tokens.
 
         // separate the input into blank-delmited tokens.
 
         list parsed = llParseString2List( message, [ " " ], [] );
 
         list parsed = llParseString2List( message, [ " " ], [] );
 
+
 
         // get the first part--the "command".
 
         // get the first part--the "command".
 
         string command = llList2String( parsed, 0 );
 
         string command = llList2String( parsed, 0 );
Line 28: Line 32:
 
         string distance_string = llList2String( parsed, 1 );
 
         string distance_string = llList2String( parsed, 1 );
 
         float distance = ( float )distance_string;
 
         float distance = ( float )distance_string;
+
 
 
         vector position = llGetPos();
 
         vector position = llGetPos();
+
 
 
         if( command == "up" )
 
         if( command == "up" )
 
         {
 
         {
Line 58: Line 62:
 
  }
 
  }
  
'''Status:''' Not working. The list type has not been implemented (and thus, llList2String() and llParseString2List())
+
'''Status:''' Working!
 +
 
 +
[[Category:Scripts]]

Latest revision as of 20:29, 3 March 2012


Code:

vector startPosition;
float groundLevel;
 
default
{
   state_entry() 
   {
       llListen( 0, "", llGetOwner(), "");

       startPosition = llGetPos();
       groundLevel = llGround( startPosition );
   
       llSay( 0, "Control this object with chat commands like:" );
       llSay( 0, "'up' or 'down' followed by a distance." );
   }  
     
   listen( integer channel, string name, key id, string message ) 
   {
       // separate the input into blank-delmited tokens.
       list parsed = llParseString2List( message, [ " " ], [] );

       // get the first part--the "command".
       string command = llList2String( parsed, 0 );
       
       // get the second part--the "distance".
       string distance_string = llList2String( parsed, 1 );
       float distance = ( float )distance_string;
 
       vector position = llGetPos();
 
       if( command == "up" )
       {
           if( ( position.z + distance ) < (startPosition.z + 10.0 ) )
           {
              llSetPos( llGetPos() + < 0, 0, distance > ); // move up
              llSetText( "Went up " + (string)distance, < 1, 0, 0 >, 1 );
           }
           else
           {
              llSetText( "Can't go so high.", < 1, 0, 0 >, 1 );
           }
       }
       else if( command == "down" )
       {
           if( ( position.z - distance ) > groundLevel ) 
           {
              llSetPos( llGetPos() + < 0, 0, -distance > ); // move down
              llSetText( "Went down " + (string)distance, < 1, 0, 0 >, 1 );
           }
           else
           {
              llSetText( "Can't go so low.", < 1, 0, 0 >, 1 );
           }
       }    
   }
}

Status: Working!

Personal tools
General
About This Wiki