Friday, December 05, 2008
USERLOGIN PASSWORD Remember?
You are here » Learning Center ยป Forums

Openlife Forums

 Openlife Grid Forums
Minimize
 
  Openlife Forums  Scripting  Openlife LSL Ex...  A sample notecard reader and displayer with osDrawing functions.
Previous Previous
 
Next Next
New Post 6/22/2008 11:29 AM
User is offline salahzar
14 posts
Openlife Newbie


A sample notecard reader and displayer with osDrawing functions. 
Modified By salahzar  on 6/22/2008 11:31:07 AM)

Here a very simple script able to read notecards. and display them paging and breaking them with different fonts.

How it works:

Simply drop a (only one!) notecard in the object repository. Script when reset (you can say "RESET" on public chat for resetting).will read the notecard.

Every time you touch the object it will go one page further.

You can easily change the fontsize (look at the code), and in next version of opensim you can change the font :)

 

 

Notes:

1\ it uses undocumented functions on osDrawing. I'll try to also document them properly, maybe in the opensim wiki

2\ it uses an undocumented feature of notecard reading I've found reverse engineering the opensim code. I'm a bit afraid the programmers will change this, so I need to be in touch with some scripters to know how notecard reading is going on.

salahzar

 

 

//
// Note: very important:
// drawing starts with x->    y v where x, y are in the range 0..255


string drawList="";
integer offset=1;
integer fontsize=10;
integer row=0;
integer rows;
integer cols;
integer start=0;

add(string str)
{
    drawList = osMovePen(drawList, offset, (fontsize+2)*row+offset);
    row++;
    drawList = osDrawText (drawList, str );
}

default
{
    state_entry()
    {
        string nc=llGetInventoryName(INVENTORY_NOTECARD,0);
        integer lines=llGetNumberOfNotecardLines(nc);
       
        llSetText("Click for changing page\n# of lines: "+(string)lines,<1,1,1>,1);
        // number of rows
        rows=255/(fontsize+2)-1;
        cols=rows*2.5;
        start=0;
        row=0;
        llOwnerSay("**Reset.. Fontsize: "+(string)fontsize+" Notecard: "+llGetInventoryName(INVENTORY_NOTECARD,0)+" **");
        llListen(0,"",llGetOwner(),"");
       
    }
   
    touch_start(integer count)
    {
        //drawList = osSetFontName(drawList,"Courier");
        drawList ="";
        drawList = osSetFontSize (drawList, fontsize ); row=0;
        integer wbline=0;
        string nc=llGetInventoryName(INVENTORY_NOTECARD,0);
        integer lines=llGetNumberOfNotecardLines(nc);
        if(start>=lines)
        {
            llOwnerSay("Restarting from top");
            start=0;
        }
       
        while( start < lines )
        {
            string data=llGetNotecardLine(nc,start+1);
       
            integer i;
            integer numrows=llStringLength(data)/cols; // number of rows to use
            integer offset=0;
            for(i=0;i<=numrows;i++){
               string str=llGetSubString(data,offset,offset+cols-1);
               if(str!=""){
                  wbline++;
                  if(wbline<rows) {                  
                     //llOwnerSay((string)start+"-"+(string)wbline+":"+str);                  
                     add(str);
                     offset+=cols;
                  } else {
                     osSetDynamicTextureData("", "vector", drawList, "", 0);
                     return;
                    
                  }
               }
            }
           
           
            // fetch next line
            start++;
        }
        osSetDynamicTextureData("", "vector", drawList, "", 0);
       
       
    }
    listen(integer channel,string str, key id, string data)
    {
        if(data=="RESET")
        {
            llResetScript();
            return;
        }
    }
}

 

 
New Post 6/23/2008 5:01 PM
User is offline Gobi Greenwood
21 posts
Openlife Newbie


Re: A sample notecard reader and displayer with osDrawing functions. 

salahzar,

 

thanks for bringing your wizardry to openlife! 

I've been a user and a fan of your products in SL for many months now and am looking forward to seeing the tools and products you create here in openlife as well.  Welcome!

 

 

 
Previous Previous
 
Next Next
  Openlife Forums  Scripting  Openlife LSL Ex...  A sample notecard reader and displayer with osDrawing functions.
Privacy Statement | Terms Of UseAll Rights Reserved 2007,2008 3DX - Openlifegrid.com