Jump to content

notice board script with automatic line breaks


testgenord1
 Share

You are about to reply to a thread that has been inactive for 1521 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi!
I've got a script that uses notecards and displays the text on these notecards on its textures, as a kind of notice board.

It automatically adds some line-breaks when the sentence is too long for the surface area.

Unfortunately, this does not always work, which means sometimes the last letters of a word disappear.
Maybe one of you has an idea of how to change this part, so that the words are no longer cut off at the end?

Thank you very much in advance.
Here is the script:

string title = "";
string subtitle = "";
string text = "";
string add = "";
integer xt = 40; // position x titre
integer ligne;
integer ligne2;
integer ligne3;
integer ligne4;
integer ligne5;
key demandetitre;
key demandesub;
key demandetext;
key demandeimg;
key demandeoption;
string color;
string color2;
string color3;
string color4;
integer imgw;
integer imgh;
integer imgx;
integer imgy;
integer fin;
integer alpha;

push_text2()
{
    draw_text();    
}
draw_text()
{
    string drawList ="";
    if (add!="")
    {
    drawList += "MoveTo " + imgx + ", " + imgy + ";Image " + imgw + ", " + imgh + "," + add + ";"; 
    }
    drawList += "MoveTo "+xt+",80; PenColour " + color + "; FontSize 48; Text " + title + ";";
    drawList += "MoveTo 40,160;  PenColour " + color2 + "; FontSize 32; Text " + subtitle + ";";
    drawList += "PenColour " + color3 + "; MoveTo 40,220; FontSize 24; Text " + text + ";";
    osSetDynamicTextureData("", "vector", drawList, "width:1024,height:1024,alpha:"+alpha+",bgcolour:"+color4, 255);  
}
 
default {
    on_rez (integer rez)
    {
       llResetScript();        
    }
    state_entry()
    {       
    }
   dataserver(key requested,string message)
    {
      integer nbrchar;
      integer i=0;
      integer j;
      integer k;
      string com;
      string message2;
    
      if (requested==demandetitre&&message!=EOF)
       {
            if (ligne==1) 
            {
               color=message; 
            }
            else
            {
                nbrchar=llStringLength(message);  
                if (nbrchar>25)
                {
                    title="ERROR";
                    xt=512-(8/2*38+40);  
                }
                else
                {
                    title=message;
                    title=llToUpper(title);
                    xt=512-(nbrchar/2*38+40);  
                } 
            }
                demandetitre=llGetNotecardLine("Title",ligne++);
        }  
        if (requested==demandesub&&message!=EOF)
        {  
            if (ligne2==1)
            {
                color2=message; 
            }
            else
            {
                nbrchar=llStringLength(message);
                if (nbrchar>37)
                {
                    subtitle="ERROR";   
                }
                else
                {
                    subtitle=message; 
                }        
            }  
                demandesub=llGetNotecardLine("Subtitle",ligne2++);       
        }                                                                                       
        if (requested==demandetext&&message!=EOF)
        {  
            if (ligne3==1)
            {
                color3=message;
            }
            else
            {
                nbrchar=llStringLength(message);
                if (nbrchar>60)
                {
                    i=nbrchar/60;
                    message2=message;
   
                    for (j=i ; j>0 ; j--)
                    {
                        k=j*60;
                        message2=llInsertString(message2,k,"-\n");
                    }
                    message2 += "\n";
                    text += message2;
                }
                else
                {
                    text += message;
                    text += "\n";
                }  
            }  
                demandetext=llGetNotecardLine("Text",ligne3++);       
        }                                                                                                                         
        if (requested==demandeimg&&message!=EOF)
        {  
            if (ligne4==1)
            {
                imgw=(integer)message;  
            }
            if (ligne4==2)
            {
                imgh=(integer)message;
            }
            if (ligne4==3)
            {
                imgx=(integer)message;  
            }
            if (ligne4==4)
            {
                imgy=(integer)message;
            }
            if (ligne4>4)
            {
                add=message;  
            }  
                demandeimg=llGetNotecardLine("Picture",ligne4++);       
        }                                                                                        
        if (requested==demandeoption&&message!=EOF)
        {  
            if (ligne5==1)
            {
                alpha=(integer)message;
            }
            if (ligne5==2)
            {
               color4=message; 
            }
                demandeoption=llGetNotecardLine("Option",ligne5++);       
        }         
        if (message==EOF)
        {
            fin++;
        }
        if (fin==5)
        {
            push_text2();
        }                                
    }
    changed (integer change)
    {
        if (change & CHANGED_INVENTORY)
        {
        ligne=0;
        ligne2=0;
        ligne3=0;
        ligne4=0;
        ligne5=0;
        text="";
        title="";
        subtitle="";
        add="";
        fin=0;
        alpha=0;
   
        demandetitre=llGetNotecardLine("Title",ligne++);
        demandesub=llGetNotecardLine("Subtitle",ligne2++);
        demandetext=llGetNotecardLine("Text",ligne3++);
        demandeimg=llGetNotecardLine("Picture",ligne4++);
        demandeoption=llGetNotecardLine("Option",ligne5++);
        }
    } 
}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1521 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...