Jump to content

Item Giver Fix


Reymundo
 Share

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

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

Recommended Posts

So I found the following free script online but it has a limit of 22 items, how do I fix that? The script is as follows...

 

list object_list; 
list object_list2; 
key user = NULL_KEY; 

composelist() 
{ 
    integer currentobject = 0; 
    integer totalobjects = llGetInventoryNumber(INVENTORY_OBJECT); 
     
    if(totalobjects > 0 & totalobjects <= 12) 
    { 
        object_list = []; 
        do 
        { 
            object_list = object_list + llGetInventoryName(INVENTORY_OBJECT, currentobject); 
            currentobject++; 
        } 
        while (currentobject > 0 & currentobject < totalobjects); 
    } 
     
    if(totalobjects > 12 & totalobjects <= 22) 
    { 
        object_list = ["Next Page"]; 
        do 
        { 
            object_list = object_list + llGetInventoryName(INVENTORY_OBJECT, currentobject); 
            currentobject++; 
        } 
        while (currentobject > 0 & currentobject < 11); 
         
        object_list2 = ["Last Page"]; 
        do 
        { 
            object_list2 = object_list2 + llGetInventoryName(INVENTORY_OBJECT, currentobject); 
            currentobject++; 
        } 
        while (currentobject >= 11 & currentobject < totalobjects); 
    } 
     
    if(totalobjects > 22) 
    { 
        llWhisper(0, "You may only have a maximum of 22 Objects. Please remove any extra ones.");
    } 
    if(totalobjects == 0) 
    { 
        llWhisper(0, "Please add up to 22 Objects to give away. They should be Copy/Transfer.");
    } 
} 


//The Menu 
integer menu_handler; 
integer menu_channel; 
menu(key user,string title,list object_list) 
{ 
    menu_channel = (integer)(llFrand(99999.0) * -1); //random channel 
    menu_handler = llListen(menu_channel,"","",""); 
    llDialog(user,title,object_list,menu_channel); 
    llSetTimerEvent(30.0); //menu channel open for 30 seconds 
} 

default 
{ 
    state_entry() 
    { 
        composelist(); //make list from inventory objects 
    } 

    touch_start(integer total_number) 
    { 
        user = llDetectedKey(0); 
        menu(user,"nnPlease select one below.",object_list); 
    } 
     
    listen(integer channel,string name,key id,string message) 
    { 
        if (channel == menu_channel)  
        {             
            if(message == "Next Page") 
            { 
                menu(user,"nnPlease select one below.",object_list2); 
            } 
            else if(message == "Last Page") 
            { 
                menu(user,"nnPlease select one below.",object_list); 
            } 
            else 
            { 
                llGiveInventory(user,message); //Give Object 
                llSetTimerEvent(0.0); 
                llListenRemove(menu_handler); 
            } 
        } 
    } 
     
    timer() //Close the Menu Listen or we'll get laggy 
    { 
        llSetTimerEvent(0.0);  
        llListenRemove(menu_handler); 
    } 
     
    changed(integer change)  
    { 
        if (change & CHANGED_INVENTORY) //inventory has changed 
        { 
            llSleep(0.5); 
            composelist(); //rebuild the list 
        } 
    } 
}
Link to comment
Share on other sites

You can either add another page worth of menu by essentially inserting another block of code between "Next Page" and "Last Page", or you can use a different script that is designed to take a non-specific number of menu pages.  Or you can start writing your own scripts. That's easier in the long run than trying to figure out how someone else's works. :smileywink:

Link to comment
Share on other sites

Well when I tried doing what you suggested, I was getting syntax errors. Hence why I'm asking, as for writing the script myself I wouldn't know how, I only know how to edit LSL. If you could possibly explain what I would add and where that would be appreciated.

Link to comment
Share on other sites

A script is nothing more than a map of the logic for performing a series of tasks. So, if you want to modify an existing script, you need to work through the logic that it represents.  In this case, the pagination is all handled in the Composelist routine at the top of the script.  Specifically, look at the two blocks here:

if(totalobjects > 0 & totalobjects <= 12)     {         object_list = [];         do         {             object_list = object_list + llGetInventoryName(INVENTORY_OBJECT, currentobject);             currentobject++;         }         while (currentobject > 0 & currentobject < totalobjects);     }          if(totalobjects > 12 & totalobjects <= 22)     {         object_list = ["Next Page"];         do         {             object_list = object_list + llGetInventoryName(INVENTORY_OBJECT, currentobject);             currentobject++;         }         while (currentobject > 0 & currentobject < 11);                  object_list2 = ["Last Page"];         do         {             object_list2 = object_list2 + llGetInventoryName(INVENTORY_OBJECT, currentobject);             currentobject++;         }         while (currentobject >= 11 & currentobject < totalobjects);     }

The first one tells the script how to create a menu when there are 12 elements or fewer.  The second one tells how to create a menu when there are more than 12 but fewer than 23. Notice that the second block contains two sub-blocks, one for the first page and one for the second page. So... suppose that you wanted to create a third block, with three sub-blocks.....  You see how the second one works, so follow the same logic by extension.

This approach for writing a multipage menu is really quite clumsy, because it means writing increasingly long blocks of extra code each time you want to add another chunk of list elements.  Basically, the logic is simply using the same code over and over and over again.  It would be much smarter to write a script that is designed from the start to handle an indefinite number of elements, dividing them up into pages automatically instead of needing these repeated blocks of code.  That's why I suggested using a totally different script.  The LSL Scripting Library has several different multipage examples other than the one I  linked to earlier.

Incidentally, syntax errors are usually the easy ones to fix.  They're just telling you that you made the coding equivalent of a spelling error.  The clumsy in-world editor will point you to the place where the error occurs, even if it doesn't tell you explicitly what you screwed up. Most often, you'll discover that you really haven't done anything more serious than making a typo or forgetting to count the number of matching brackets.  The more serious errors are the errors of logic, where you haven't mapped out what's in your head clearly enough.  Those can take ages to fix, but they are truly satisfying once you beat them to a pulp.  That's 90% of what scripting is about, IMO.

Link to comment
Share on other sites

here is something close, it uses Void's dialog code (modified)

from this page ....  http://wiki.secondlife.com/wiki/User:Void_Singer/Functions

it should give you 9 buttons per page, plus 1-3 control buttons, and ( 21? ) pages that cycle

from last back to first.

 

 

list object_list;  key user = NULL_KEY; string txt;string name;integer handle;integer chan;integer idx;list gLstMnu;composelist() {     integer currentobject = 0;     integer totalobjects = llGetInventoryNumber(INVENTORY_OBJECT);         object_list = [];         do         {   name = llGetInventoryName(INVENTORY_OBJECT, currentobject);             name = llGetSubString(name, 0, 23) ;  // button charachter limit            object_list += name;            currentobject++;         }         while (currentobject > 0 & currentobject < totalobjects);         gLstMnu =  object_list; } list uDlgBtnLst( integer vIdxPag ){    list vLstRtn;    if ((gLstMnu != []) > 9)    {   integer vIntTtl = -~((~([] != gLstMnu)) / 9);                                 //-- Total possible pages        integer vIdxBgn = (vIdxPag = (vIntTtl + vIdxPag) % vIntTtl) * 9;              //-- first menu index        string  vStrPag = llGetSubString( "                     ", 21 - vIdxPag, 21 ); //-- encode page number as spaces            vLstRtn = llListInsertList( llList2List( gLstMnu, vIdxBgn, vIdxBgn + 8 ),         (list)(" «" + vStrPag), vIdxBgn + 9 ) + "CLOSE" + (list)(" »" + vStrPag);    }    else    { vLstRtn = gLstMnu + [" ", "CLOSE"," "]  ;    }    return //-- fix the order for [L2R,T2B] and send it out      llList2List( vLstRtn, -3, -1 ) + llList2List( vLstRtn, -6, -4 ) +      llList2List( vLstRtn, -9, -7 ) + llList2List( vLstRtn, -12, -10 );}default {     state_entry()     {       composelist(); //make list from inventory objects       chan = (integer)(llFrand(99999.0) * -1); //random channel       txt = "\n \nMain Menu\n" +                          "\n CLOSE - closes this menu\n" +             "\n Please select one below . ";    }     touch_start(integer total_number)     {         user = llDetectedKey(0);         llDialog( user, txt, uDlgBtnLst( 0 ), chan );        handle = llListen(chan,"","","");        llListenControl(handle, TRUE);         llSetTimerEvent(20);    }             listen( integer vIntChn, string vStrNom, key vKeySpk, string vStrMsg )    {        if (!llSubStringIndex( vStrMsg, " " ))        {  llDialog( vKeySpk, txt,                     uDlgBtnLst( llStringLength( vStrMsg ) +                     llSubStringIndex( vStrMsg, "»" ) - 2 ),                     vIntChn );           llSetTimerEvent(20);                   }                  else if (vStrMsg == "CLOSE")        {   llSetTimerEvent(0.5);        }        else        {               llGiveInventory(user,vStrMsg); //Give Object                             idx =  llListFindList( gLstMnu, (list)vStrMsg )  / 9;            llDialog( user, txt, uDlgBtnLst(idx ), chan );            llSetTimerEvent(20);        }    }         timer()     {         llSetTimerEvent(0.0);          llListenControl(handle, FALSE);     }          changed(integer change)      {         if (change & CHANGED_INVENTORY) //inventory has changed         {             llSleep(0.5);             composelist(); //rebuild the list         }     } }

 

Link to comment
Share on other sites

I will try that script Xiija, as far as the other. I was attempting to copy the portion where it says what to do for 12-22 items, and then add 23-33, etc. That was where it was giving me syntax and I couldn't figure out what the particular issue was as I have found that it can mention one line, but it's actually another line altogether. Also the link you gave before Rolig didn't seem like it gave out items like the script I provided did.

 

EDIT: So it kinda worked but I'm using no copy items so it ended up popping up a script error.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2663 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...