Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to build a dynamic llDialog?

Alberrt Steptoe
Second Life Resident
Join date: 31 Oct 2004
Posts: 19
03-28-2009 13:41
Hiya,

Ok, I want to create an object which will build a list based on its inventory, The list will inturn be used for the llDialog();

Could be quite a lot of entries. Wouldn't say more than 40 or 50 but needs to be capable of going some above that if needed I should imagine it will run at about 10-20 at a time.

I understand memory management could be an issue so I will create some kind of memory management to go with it.

I dont want anyone to write it for me but would like some pointers on where to start with constructing a dynamic lldialog()

Really I will need maybe a maximum of 8 buttons per pop up box as I will need to add some button for ["Prev", "Main", "Next", "Close"].

Dont know about you guys but I like the close button so if they bail out of the menu early I can remove the listen.


Thanks guys.

- Alberrt
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
03-28-2009 21:28
use a data_server event to read in each item name and add it to a list... i.e. itemsList.
Then using a for loop, read the first eight entries into a dialog list....i.e. dialogList and keep track of the list position with a pointer. For example, read in the first 8 items, list item 0 thru list item 7, then set a pointer to 0, because that's the first item in the first set, let's call the pointer pointer to keep it simple.

Then, when you call llDialog(), you call it with that short (8 item) list.
llDialog( avatar, message, dialogList, chat_channel );

then, in your listen event, if they choose "next", then add 8 to the pointer, and clear the dialog list (dialogList = []), then read the next 8 entries using your pointer....

for (i=pointer; i < pointer + 8, pointer++)

and add the next 8 to the dialogList and call llDialog() again.

Do the same for "previous" except subtract 8 instead of add.
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
03-29-2009 01:39
there are at least three examples of dynamic dialogs on the forum off the top of my head. search llDialog menu dynamic multipage

or use this as a starting point
CODE

//--// v7-D Menued Item Giver w/ MultiPage Dialog Support v1.2 //--//

//-- Edit Next 2 lines.. first is text for dialog, second is folder for "give all"
string cSTR_MESSAGE = "Welcome to XXX, Please choose any free item you'd like below";
string cSTR_FOLDER = "Freebies from XXX";
integer cINT_DIALOG_CHANNEL = -42;

list vgLstButtons;

list vfParseButtons( integer vIntPage ){
list vLstReturn;
integer vIntLength = llGetListLength( vgLstButtons );
integer vIntStart = llAbs(vIntPage) * 11;

if (vIntLength - vIntStart > 1){
if (vIntLength - vIntStart > 12){
vLstReturn += llList2List( vgLstButtons, vIntStart + 9, vIntStart + 10 );

if (vIntPage < 10){
vLstReturn += ["MORE (0" + (string)(vIntPage + 1) + ")"];
}
else{
vLstReturn += ["MORE (" + (string)(vIntPage + 1) + ")"];
}
vLstReturn += llList2List( vgLstButtons, vIntStart + 6, vIntStart + 8 );
vLstReturn += llList2List( vgLstButtons, vIntStart + 3, vIntStart + 5 );
vLstReturn += llList2List( vgLstButtons, vIntStart, vIntStart + 2 );
}
else{
integer i = vIntLength - 1;
for (i; i - 2 >= vIntStart; i -= 3){
vLstReturn += llList2List( vgLstButtons, i -2, i );
}
if (i >= vIntStart){
vLstReturn += llList2List( vgLstButtons, vIntStart, i );
}
}
}
return vLstReturn;
}

default{
state_entry(){
llOwnerSay( "Creating Item List..." );
integer i = 0;
integer vIntItems = llGetInventoryNumber( INVENTORY_ALL );
vgLstButtons += "TAKE ALL!";
string vStrScriptName = llGetScriptName();
for (i; i < vIntItems; ++i){
string vStrTemp = llGetInventoryName( INVENTORY_ALL, i );
if (vStrTemp != vStrScriptName){
if (llStringLength( vStrTemp ) < 24){
vgLstButtons += [vStrTemp];
}
else{
llOwnerSay( "Item \"" + vStrTemp + "\" not added; Name is too long (24+)" );
}
}
}
llOwnerSay( (string)vIntItems + " Items Available. Freebie Giver Started" );
state vsWorking;
}
}

state vsWorking{
state_entry(){
}

touch_start( integer vIntTouched ){
llListen( cINT_DIALOG_CHANNEL, "", llDetectedKey( 0 ), "" );
llSetTimerEvent( 30.0 );
llDialog( llDetectedKey( 0 ),
cSTR_MESSAGE,
vfParseButtons( 0 ),
cINT_DIALOG_CHANNEL );
}

listen( integer vIntChannel, string vStrName, key vKeyID, string vStrMessage ){
if (llGetSubString( vStrMessage, 0, 5 ) == "MORE ("){
llSetTimerEvent( 30.0 );
llDialog( vKeyID,
cSTR_MESSAGE,
vfParseButtons( (integer)llGetSubString( vStrMessage, 6, 7 ) ),
cINT_DIALOG_CHANNEL );
}
else if ( vStrMessage == "TAKE ALL!"){
llGiveInventoryList( vKeyID, cSTR_FOLDER, llList2List( vgLstButtons, 1, -1 ) );
}
else{
llGiveInventory( vKeyID, vStrMessage );
}
}

timer(){
llSetTimerEvent( 0.0 );
state vsListenKill;
}

changed( integer vBitChanged ){
if (vBitChanged & (CHANGED_OWNER | CHANGED_INVENTORY)){
llOwnerSay( "Owner/Inventory Changed, Resetting..." );
llResetScript();
}
}
}

state vsListenKill{
state_entry(){
state vsWorking;
}
}
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
ElQ Homewood
Sleeps Professionally
Join date: 25 Apr 2007
Posts: 280
03-29-2009 04:17
Check out http://wiki.secondlife.com/wiki/Inventory_Menu. It builds the dialog dynamically, while still giving you control of the number of possible items. Not a bad place to start.