Event test script

From Second Life Wiki
Jump to: navigation, search

To do:

  • object_rez
  • email
  • link_message
  • not_at_target
  • at_target
  • remote_data

<lsl> integer touch_start_pass = FALSE; integer touch_over_pass = FALSE; key ds_request; integer control_state = 0; key http_request; string http_url="http://www.google.com"; integer collision_state = 0; integer land_collision_state = 0; integer rot_target_state = 0; integer moving_state = 0; default {

   state_entry()
   {
       llSetStatus(STATUS_PHYSICS, FALSE);
       llSay(0, "Take me in to your inventory and then rez.");
   }

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_exit()
   {
       //llSay(0, "Initial state test success (on_rez, state_exit)");
   }

}

state test_touch {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry()
   {
       llSay(0, "Touch me!");
       touch_start_pass = FALSE;
       touch_over_pass = FALSE;
   }
   
   touch_start(integer num_detected)
   {
       touch_start_pass = TRUE;
   }
   
   touch(integer num_detected)
   {
       touch_over_pass = TRUE;
   }
   
   touch_end(integer num_detected)
   {
       if (touch_start_pass && touch_over_pass)
       {
           state test_money;
       }
       else
       {
           llSay(0, "Touch test failed.");
       }
   }
   state_exit()
   {
       llSay(0, "Touch test success");
   }

}

state test_money {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   state_entry()
   {
       llSay(0, "Give me some L$.");
   }
   
   money(key giver, integer amount) {
       state test_listen;
   }
       
   state_exit()
   {
       //llSay(0, "Money test success");
   }
 

}

state test_listen {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry()
   {
       llSay(0, "say, \"hello\"");
       llListen( 0, "", NULL_KEY, "" ); 
   }
   listen( integer channel, string name, key id, string message )
   {
       // TODO perhaps store the id of the person who kicked off the tests and check that against id
       if (channel == 0 && message == "hello")
       {
           state test_dataserver;
       }
   }
   
   state_exit()
   {
       //llSay(0, "Listen test passed");
   }

}


state test_dataserver {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       //llSay(0, "Looking up your SL creation date.");
       ds_request = llRequestAgentData(llGetOwner(), DATA_BORN); // request your SL creation date
   }
   
   dataserver(key queryid, string data) 
   {
       if( ds_request == queryid )
       {
           llSay(0, "You were born on " + data);
           state test_perms_and_controls;
       }
   }
   
   state_exit()
   {
       //llSay(0, "dataserver test passed");
   }

}

// TODO make this two seperate tests state test_perms_and_controls {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry()
   {
       control_state = 0;
       llSay(0, "Grant permissions for control.");
       llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
   }
   run_time_permissions(integer perm)
   {
       if (perm & (PERMISSION_TAKE_CONTROLS))
       {
           llTakeControls(CONTROL_FWD|CONTROL_BACK|CONTROL_LEFT|CONTROL_RIGHT, TRUE, FALSE);
           llSay(0, "Press Forward (you may need to to go mouse look)");
       }
   }
   
   control(key id, integer held, integer change)
   {
       if ((held & change & CONTROL_FWD) && control_state == 0)
       {
           llSay(0, "Press Left");
           ++control_state;
       }
       if ((held & change & CONTROL_LEFT) && control_state == 1)
       {
           llSay(0, "Press Back");
           ++control_state;
       }         
       if ((held & change & CONTROL_BACK) && control_state == 2)
       {
           llSay(0, "Press Right");
           ++control_state;
       } 
       if ((held & change & CONTROL_RIGHT) && control_state == 3)
       {
           llReleaseControls();
           state test_timer;
       } 
          
   }
   
   state_exit()
   {
       //llSay(0, "control and perms test");
   }

}

state test_timer {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       //llSay(0, "Timer test start");
       llSetTimerEvent(1.0);
   }
   
   timer() 
   {
       llSetTimerEvent(0.0);
       state test_http;
   }    
       
   state_exit()
   {
       //llSay(0, "Timer test end");
   }

}

state test_http {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       //llSay(0, "http test start");
       http_request = llHTTPRequest(http_url, [] ,"");
   }
   
   http_response(key id,integer status, list meta, string body)
   {
       if(http_request == id)
       {
           state test_land_collision;
       }
   }    
       
   state_exit()
   {
       //llSay(0, "http test end");
   }

}

state test_land_collision {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       //llSay(0, "land collision test start");
       llSetStatus(STATUS_PHYSICS, TRUE);
       land_collision_state = 0;
   }
   
   land_collision_start(vector pos)
   {
       //llSay(0, "land_collision_start");
       if (land_collision_state == 0)
       {
            ++land_collision_state;
       }
   }
   land_collision(vector pos)
   {
       //llSay(0, "land_collision");
       if (land_collision_state == 1)
       {
           ++land_collision_state;
       }
   }
   
   land_collision_end(vector pos)
   {
       //llSay(0, "land_collision_end");
       if (land_collision_state == 2)
       {
           llSetStatus(STATUS_PHYSICS, FALSE);
           state test_rot_target;
       }
   }
           
   state_exit()
   {
       //llSay(0, "land collision test end");
   }    

}


state test_rot_target {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       //llSay(0, "test_rot_target");
       integer rot_handle = llRotTarget(<0,0,0,1>, 0); 
       rot_target_state = 0;
   }
   
   not_at_rot_target()
   {
       //llSay(0, "not_at_rot_target");
       if (rot_target_state == 0)
       {
           integer rot_handle = llRotTarget(<0,0,0,1>, 7); 
           rot_target_state = 1;
       }
   }
   
   at_rot_target(integer tnum, rotation targetrot, rotation ourrot)
   {
       //llSay(0, "at_rot_target");
       if (rot_target_state == 1)
       {
           rot_target_state = 2;
           state test_collision;
       }            
   }
 
   state_exit()
   {
       //llSay(0, "rot_target test end");
   }    

}


state test_collision {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       llSay(0, "Walk in to the box");
       llSetStatus(STATUS_PHYSICS, TRUE);
       collision_state = 0;
   }
   
   collision_start(integer num_detected)
   {
       //llSay(0, "collision_start");
       if (collision_state == 0)
       {
            ++collision_state;
       }
   }
   collision(integer num_detected)
   {
       //llSay(0, "collision");
       if (collision_state == 1)
       {
           ++collision_state;
       }
   }
   
   collision_end(integer num_detected)
   {
       //llSay(0, "collision_end");
       if (collision_state == 2)
       {
           llSetStatus(STATUS_PHYSICS, FALSE);
           state test_attach;
       }
   }
           
   state_exit()
   {
       //llSay(0, "land collision test end");
   }    

}

state test_attach {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       llSay(0, "Attach to yourself");
   }
   
   attach(key attached)
   {
       if (attached == NULL_KEY) 
       {
           state test_change;
       }
       else
       {
           llSay(0, "Drop me.");
       }
   }
           
   state_exit()
   {
       //llSay(0, "land collision test end");
   }    

}

state test_change {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       llSetColor(<1,1,1>, ALL_SIDES);
   }
   
   changed(integer change)
   {
       if (change & CHANGED_COLOR)
       {
           state test_moving;
       }
   }
           
   state_exit()
   {
   }    

}

state test_moving {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       llSay(0, "Move me, then place somewhere flat");
       moving_state = 0;
       llSetStatus(STATUS_PHYSICS, TRUE);
   }
           
   state_exit()
   {
       llSetStatus(STATUS_PHYSICS, FALSE);
   } 
   
   moving_start() 
   {
       moving_state = 1;
   }
       
   moving_end() 
   {
       if (moving_state == 1)
       {
           state test_sensor;
       }
   }   

}

state test_sensor {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   
   state_entry() 
   {
       llSay(0, "Move avatar at least away 1m");
       llSensor("", NULL_KEY, AGENT, 1, PI); 
   }
           
   state_exit()
   {
       
   } 
   
   sensor(integer total_number)
   {
       state test_end;
   }  
   
   no_sensor() 
   {
       llSensor("", NULL_KEY, AGENT, 10, PI); 
   }

}

state test_end {

   on_rez(integer start_param)
   {
       state test_touch;
   }
   state_entry()
   {
       llSay(0, "All states/tests completed. Success!");
   }   

}

</lsl>