GetLessonPages

From SLIS Second Life Wiki
Jump to: navigation, search
Back to Sloodle API


Function: getLessonPages
Description: Returns a list of lesson pages for the lesson specified along with page data
llMessageLinked(LINK_SET, PLUGIN_CHANNEL, "plugin:lessons,function:getLessonPages\nSLOODLEID:null\nindex:0|lessonsPerPage:9|lessonid:1", NULL_KEY);
Parameters:
SLOODLE_ID:null this is left as null because we aren't accessing a specific activity
INDEX: The index of the lesson page you'd like to start from
ITEMS_PER_PAGE: The number of items you'd like to appear in the output
LESSON ID: The id of lesson you want pages from


Output: GetlessonPages.jpg


Example Script:
 	 /*********************************************
*  Copyright (c) 2009 Paul Preibisch
*  Released under the GNU GPL 3.0
*  This script can be used in your scripts, but you must include this copyright header as per the GPL Licence
*  For more information about GPL 3.0 - see: http://www.gnu.org/copyleft/gpl.html
* 
*
*  This script is part of the SLOODLE Project see http://sloodle.org
*
*  Copyright:
*  Paul G. Preibisch (Fire Centaur in SL)
*  fire@b3dMultiTech.com  
*
* API DEMO OBJECT
* getLessonPages.lsl 
* 
* PURPOSE
*  This script is part of the SLOODLE HQ.
*  
/**********************************************************************************************/
key owner;
// *************************************************** HOVER TEXT VARIABLES
integer DISPLAY_DATA                                                        =-774477; //every time the display is updated, data goes  on this channel
integer PLUGIN_RESPONSE_CHANNEL                                =998822; //sloodle_api.lsl responses
integer PLUGIN_CHANNEL                                                    =998821;//sloodle_api requests
integer SLOODLE_CHANNEL_TRANSLATION_REQUEST     = -1928374651;//translation channel
integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE     = -1928374652;//translation channel
integer SLOODLE_CHANNEL_OBJECT_DIALOG                     = -3857343;//configuration channel

/***********************************************
*  getFieldData-- returns data from a table based on the column name
***********************************************/
string getFieldData(list tableRowData, string colName){
   return llList2String(tableRowData,llListFindList(tableRowData, [colName])+1);
} 
/***********************************************
*  s()  used so that sending of linked messages is more readable by humans.  Ie: instead of sending a linked message as
*  GETDATA|50091bcd-d86d-3749-c8a2-055842b33484 
*  Context is added instead: COMMAND:GETDATA|PLAYERUUID:50091bcd-d86d-3749-c8a2-055842b33484
*  All this function does is strip off the text before the ":" char and return a string
***********************************************/
string s (string ss){
    return llList2String(llParseString2List(ss, [":"], []),1);
}
/***********************************************
*  k()  used so that sending of linked messages is more readable by humans.  Ie: instead of sending a linked message as
*  GETDATA|50091bcd-d86d-3749-c8a2-055842b33484 
*  Context is added instead: COMMAND:GETDATA|PLAYERUUID:50091bcd-d86d-3749-c8a2-055842b33484
*  All this function does is strip off the text before the ":" char and return a key
***********************************************/
key k (string kk){
   return llList2Key(llParseString2List(kk, [":"], []),1);
}
/***********************************************
*  counter()  used so that sending of linked messages is more readable by humans.  Ie: instead of sending a linked message as
*  GETDATA|50091bcd-d86d-3749-c8a2-055842b33484 
*  Context is added instead: COMMAND:GETDATA|PLAYERUUID:50091bcd-d86d-3749-c8a2-055842b33484
*  All this function does is strip off the text before the ":" char and return an integer
***********************************************/
integer i (string ii){
   return llList2Integer(llParseString2List(ii, [":"], []),1);
}


/* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
*
*  default state
*  In this state we wait until the rest of the scripts in this object init
*
* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */
 default{    
	        state_entry() {
 	         
 	          //set owner
 	          owner = llGetOwner();
	     }
	    link_message(integer sender_num, integer channel, string str, key id) {
	        list dataLines=llParseString2List(str, ["\n"],[]);
	        list cmdLine = llParseString2List(str, ["|"],[]);
	        string cmd=s(llList2String(cmdLine,0));
	        if (channel==PLUGIN_RESPONSE_CHANNEL){
	            if (cmd=="API READY") state go;
 	        }//endif channel=PLUGIN_RESPONSE_CHANNEL
 	    }//end linked_message event
	    /***********************************************
	    *  changed event
  	    *  |-->Every time the inventory changes, reset the script
	    *        
	    ***********************************************/
	    changed(integer change) {
	         if (change ==CHANGED_INVENTORY){         
	             llResetScript();
	         }//endif
	     }//end changed state
	}//end default state

 
	 /* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	 *
	 *  go  state
	 *  Now you can execute your logic because the api is ready
	 *
 	 * &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& */
  	  
 	state go{
	    touch_start(integer num_detected) {
	        /*********************************************************************************
	        * API CALL: getLessons:     Return all lesson pages in the course         
	        **********************************************************************************/
 	         llMessageLinked(LINK_SET, PLUGIN_CHANNEL, "plugin:lessons,function:getLessonPages\nSLOODLEID:null\nindex:0|lessonsPerPage:9|lessonid:1", NULL_KEY);
	    }
	     link_message(integer sender_num, integer channel, string str, key id) {
	         
	             if (channel==PLUGIN_RESPONSE_CHANNEL){
	                list dataLines = llParseStringKeepNulls(str,["\n"],[]);           
	                //get status code
	                list statusLine =llParseString2List(llList2String(dataLines,0),["|"],[]);
	                 integer status =llList2Integer(statusLine,0);
 	                string descripter = llList2String(statusLine,1);
	                string response = s(llList2String(dataLines,1));
	                integer index = i(llList2String(dataLines,2)); 
	                integer counter=0;
	                if (response=="lessons|getLessonPages"){
	                     //check status of returned response
	                    if (status==1){
	                        //initialize the string we will print on xy_text channel
	                        //get all of the lesson activities returned                        
	                        list lessons = llList2List(dataLines, 5,llGetListLength(dataLines)-1);                         
	                        integer len = llGetListLength(lessons);
	                        list colNames =llParseString2List(llList2String(dataLines,4), ["|"], []);
	                        integer colLen = llGetListLength(colNames);
	                        list data;
	                        for (counter=0;counter<len;counter++){
	                                 list colData=llParseString2List(llList2String(lessons,counter), ["|"], []); //parse the message into a list
	                                 integer j;
	                                 //add all data from this line into a 2 dimensional list called tableRowData:
	                                 //["nameOfColumn","value"]
	                                 list tableRowData;      
	                                for (j=0;j<colLen;j++){
	                                    tableRowData +=[llList2String(colNames,j),llList2String(colData,j)];
 	                                    llOwnerSay("// "+(string)(j+1)+") "+llList2String(colNames,j)+": "+llList2String(colData,j));
	                                 
 }
	                                   llOwnerSay("//********************************");
 	                         }//for
	                    }//status==1
	                }//endif response=="getLessons"
	             }//end if channel==PLUGIN_RESPONSE_CHANNEL
	       }//end link_message
	        
	     /***********************************************
	    *  changed event
	    *  |-->Every time the inventory changes, reset the script
	    *        
	    ***********************************************/
	    changed(integer change) {
	         if (change ==CHANGED_INVENTORY){         
	             llResetScript();
	         }//endif
	     }//end changed state
	    
	}//end state





Personal tools